Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ org_name:
# but allow to change it manually
when: false

use_variable_from_description:
type: bool
help: Allow to pass advanced variable from PR description

next_templates:
help: "Next templates to run. template path args"
# syntax:
Expand Down Expand Up @@ -89,3 +93,4 @@ _skip_if_exists:
- clear-prod.secrets.docker-compose.yml
- secrets.docker-compose.yml
- .copier-answers-personal.yml
- .gitlab/merge_request_templates/with_variable.md
5 changes: 5 additions & 0 deletions src/.gitlab-ci.yml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ stages:
before_script:
# TODO: manage mulitple preprod ?
# ref-commit slug ?
{% if use_variable_from_description %}
- ./bin/extract_mr_variable_env.py
- cat mr_variable.sh
- source mr_variable.sh
{% endif %}
- echo $AK_WORKING_DIR
- echo $AK_BASE_CACHE_DIR
- echo $AK_IS_MR
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python3
import json
import os

# pylint: disable=print-used


description = os.getenv("CI_MERGE_REQUEST_DESCRIPTION")
with open("mr_variable.sh", "w") as f:
if description and "# Variable" in description:
data = description.split("#Variable")[-1].split("```")[1]
try:
data = json.loads(data)
except Exception as e:
raise Exception(f"Fail to read the json data are \n {data} \n error: {e}")
for key, value in data.items():
if isinstance(value, (dict, list)):
# pass complex variable as a string in json
value = json.dumps(value)
f.writelines(f"export {key.upper()}='{value}'\n")
else:
print("Extract MR variable: No variable found or invalid description")
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Description

La variable "foo" peut etre personalisé et sera passé dans les variables d'environement de cette PR

Veuillez personnaliser les variables à personnaliser avant de commiter ce fichier

# Variable

```
{
"foo": "customisation",
}

```