From 0a3b14069fdd1178b1bb8bff5616b706978eb30a Mon Sep 17 00:00:00 2001 From: Tim Jaacks <tim.jaacks@seco.com> Date: Mon, 16 Oct 2023 11:02:50 +0200 Subject: [PATCH] Confluence: get only those build jobs with a corresponding successful deploy job We cannot handle build jobs and deploy jobs similarly, because all build jobs are successful usually, while not all deploy jobs necessarily have run. Get build.env only from those build job which have a corresponding successful deploy job, otherwise MACHINE and SUPPORTED_HARDWARE fields always contain the full list of built platforms, even if they might have not been deployed. --- scripts/collect_release_information.py | 79 ++++++++++++++------------ 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/scripts/collect_release_information.py b/scripts/collect_release_information.py index f14ad55a..bfbe5837 100755 --- a/scripts/collect_release_information.py +++ b/scripts/collect_release_information.py @@ -110,45 +110,50 @@ def main(): variables = {} - job_specs = [ - { - "stage": "Build", - "env_file": "build.env", - }, - { - "stage": args.deploy_stage, - "env_file": "deploy.env", - }, - ] - - for job_spec in job_specs: - # Get all successful jobs from stage - jobs = get_pipeline_jobs( - gitlab, project, args.pipeline, stage=job_spec["stage"] + # Get all successful jobs from deploy stage + deploy_jobs = get_pipeline_jobs( + gitlab, project, args.pipeline, stage=args.deploy_stage + ) + successful_deploy_jobs = [job for job in deploy_jobs if job.status == "success"] + if not successful_deploy_jobs: + exit(f"ERROR: no successful jobs found in stage '{args.deploy_stage}'") + + # Get all jobs from build stage + build_jobs = get_pipeline_jobs(gitlab, project, args.pipeline, stage="Build") + + for deploy_job in successful_deploy_jobs: + # Get job suffix after first "-" of the job name + job_suffix = f"{deploy_job.name[deploy_job.name.find('-'):]}" + + # Find build job with same suffix + build_job = None + for job in build_jobs: + if job.name.endswith(job_suffix): + build_job = job + + # Get variables from both jobs + job_env_variables = get_job_env_variables( + gitlab, project, deploy_job, "deploy.env" ) - successful_jobs = [job for job in jobs if job.status == "success"] - if not successful_jobs: - exit(f"ERROR: no successful jobs found in stage '{args.deploy_stage}'") - - for job in successful_jobs: - # Get variables from each job and prefix them with whatever comes after the - # first "-" of the job name. - job_env_variables = get_job_env_variables( - gitlab, project, job, job_spec["env_file"] + if build_job: + job_env_variables |= get_job_env_variables( + gitlab, project, build_job, "build.env" ) - suffix = f"{job.name[job.name.find('-'):].replace('-', '_')}" - variables |= add_suffix_to_dict_keys(job_env_variables, suffix) - - # Furthermore merge all machine-specific values into one space-separated - # variable. - for name in job_env_variables: - if job_env_variables[name]: - variables[name] = ( - f"{variables[name]} {job_env_variables[name]}" - if name in variables - and variables[name] != job_env_variables[name] - else job_env_variables[name] - ) + + # Append job suffix to the variables + variables |= add_suffix_to_dict_keys( + job_env_variables, job_suffix.replace("-", "_") + ) + + # Furthermore merge all machine-specific values into one space-separated + # variable. + for name in job_env_variables: + if job_env_variables[name]: + variables[name] = ( + f"{variables[name]} {job_env_variables[name]}" + if name in variables and variables[name] != job_env_variables[name] + else job_env_variables[name] + ) # Print all variables in a shell compatible form for k, v in sorted(variables.items()): -- GitLab