File tree Expand file tree Collapse file tree 4 files changed +46
-0
lines changed
{% if use_variable_from_description %}.gitlab{% endif %}/merge_request_templates Expand file tree Collapse file tree 4 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,10 @@ org_name:
5454 # but allow to change it manually
5555 when : false
5656
57+ use_variable_from_description :
58+ type : bool
59+ help : Allow to pass advanced variable from PR description
60+
5761next_templates :
5862 help : " Next templates to run. template path args"
5963 # syntax:
@@ -89,3 +93,4 @@ _skip_if_exists:
8993 - clear-prod.secrets.docker-compose.yml
9094 - secrets.docker-compose.yml
9195 - .copier-answers-personal.yml
96+ - .gitlab/merge_request_templates/with_variable.md
Original file line number Diff line number Diff line change @@ -56,6 +56,11 @@ stages:
5656before_script:
5757 # TODO: manage mulitple preprod ?
5858 # ref-commit slug ?
59+ {% if use_variable_from_description %}
60+ - ./bin/extract_mr_variable_env.py
61+ - cat mr_variable.sh
62+ - source mr_variable.sh
63+ {% endif %}
5964 - echo $AK_WORKING_DIR
6065 - echo $AK_BASE_CACHE_DIR
6166 - echo $AK_IS_MR
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ import json
3+ import os
4+
5+ # pylint: disable=print-used
6+
7+
8+ description = os .getenv ("CI_MERGE_REQUEST_DESCRIPTION" )
9+ with open ("mr_variable.sh" , "w" ) as f :
10+ if description and "# Variable" in description :
11+ data = description .split ("#Variable" )[- 1 ].split ("```" )[1 ]
12+ try :
13+ data = json .loads (data )
14+ except Exception as e :
15+ raise Exception (f"Fail to read the json data are \n { data } \n error: { e } " )
16+ for key , value in data .items ():
17+ if isinstance (value , (dict , list )):
18+ # pass complex variable as a string in json
19+ value = json .dumps (value )
20+ f .writelines (f"export { key .upper ()} ='{ value } '\n " )
21+ else :
22+ print ("Extract MR variable: No variable found or invalid description" )
Original file line number Diff line number Diff line change 1+ # Description
2+
3+ La variable "foo" peut etre personalisé et sera passé dans les variables d'environement de cette PR
4+
5+ Veuillez personnaliser les variables à personnaliser avant de commiter ce fichier
6+
7+ # Variable
8+
9+ ```
10+ {
11+ "foo": "customisation",
12+ }
13+
14+ ```
You can’t perform that action at this time.
0 commit comments