Skip to content
Snippets Groups Projects
Commit 69973c95 authored by Tim Jaacks's avatar Tim Jaacks
Browse files

Deploy: save deployed files in dotenv variable instead of dedicated file

Previously the deployed files were stored in a dedicated text file
called files.txt. Move this information to a dotenv variable called
FILES, so that we don't need special handling for it in the Confluence
stage.
parent 45d04033
No related branches found
No related tags found
1 merge request!346Deploy: save deployed files in dotenv variable instead of dedicated file
Pipeline #85912 skipped with stage
......@@ -387,10 +387,11 @@ workflow:
rules:
- when: manual
allow_failure: true
before_script:
after_script:
# Save MACHINE for confluence stage. This variable cannot be passed directly on the
# job definition level because the confluence stage is machine-independent.
- echo "MACHINE=${MACHINE}" > deploy.env
- echo "FILES=\"$(cat files.txt | tr '\n' ' ')\"" >> deploy.env
timeout: 60m
cache:
# Get the packaged artifacts from the cache
......@@ -400,7 +401,6 @@ workflow:
- release
artifacts:
paths:
- files.txt
- "**/md5sums.txt"
# Needed for later stage, but dotenv artifacts cannot be downloaded via GitLab API
- deploy.env
......
......@@ -16,18 +16,18 @@ from get_pipeline_jobs import get_pipeline_jobs
def get_job_env_variables(
gitlab: Gitlab, project: Project, jobs: list[ProjectPipelineJob], env_file: str
):
"""Get a list of deploy variables from the deploy.env files from the given deploy
jobs. If a variable is set to different values in different jobs, the values are
"""Get a list of variables from the env_file files from the given jobs.
If a variable is set to different values in different jobs, the values are
concatenated and newline-separated.
Args:
gitlab: Gitlab object
project: Gitlab project
jobs: list of deploy jobs
glob: pattern to match deployed file names against
jobs: list of jobs
env_file: name of the GitLab dotenv file to read variables from
Returns:
Dictionary of deploy variables with 'name' and 'value' fields
Dictionary of variables with 'name' and 'value' fields
"""
variables = {}
......@@ -47,7 +47,7 @@ def get_job_env_variables(
for line in lines:
name, value = line.partition("=")[::2]
value = value.strip("'")
value = value.strip("'").strip('"')
variables[name] = (
f"{variables[name]}\n{value}"
if name in variables and variables[name] != value
......@@ -57,47 +57,6 @@ def get_job_env_variables(
return variables
def get_deployed_files(
gitlab: Gitlab, project: Project, deploy_jobs: list[ProjectPipelineJob]
):
"""Get a set of deployed files matching a glob from a list of deploy jobs.
Args:
gitlab: Gitlab object
project: Gitlab project
jobs: list of deploy jobs
glob: pattern to match deployed file names against
Returns:
Set of deployed file paths
"""
artifacts = set()
deploy_list_file = "files.txt"
for job in deploy_jobs:
with tempfile.NamedTemporaryFile() as target_file:
print(
f"Downloading file {deploy_list_file} from job {job.name}",
file=sys.stderr,
)
download_job_artifact(
gitlab,
target_file.name,
deploy_list_file,
job.id,
project=project,
)
lines = [line.decode("utf-8").rstrip() for line in target_file.readlines()]
for line in lines:
artifacts.add(line)
return sorted(artifacts)
def main():
parser = argparse.ArgumentParser(description=__doc__, usage="%(prog)s [OPTIONS]")
......@@ -151,9 +110,10 @@ def main():
variables |= get_job_env_variables(gitlab, project, successful_jobs, "deploy.env")
files = get_deployed_files(gitlab, project, successful_jobs)
files = variables["FILES"].replace("\n", " ").split(" ")
html_files = set(fnmatch.filter(files, "*.html"))
html_files = fnmatch.filter(files, "*.html")
for html_file in html_files:
variables["HTML_FILES"] = (
f"{variables['HTML_FILES']}\n{html_file}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment