Skip to content
Snippets Groups Projects
Commit ae764fbc authored by Jonas Höppner's avatar Jonas Höppner
Browse files

CI: Confluence page: Fix not created mx6 section

The function that merges the variables of the different jobs, i.e:

`MACHINE="mx6"`

`MACHINE="mx6ull"`

used python `in` to check if a value already exists.
But `"mx6" in "mx6ull"` is true, so mx6 was dropped.
This rewrites it, storing the variables in a set (which is unique
automatically) instead of space seperated strings.
Space seperation is added before printing the variables to be used on
on the shell.
parent 094983ae
No related branches found
No related tags found
1 merge request!387CI: Confluence page: Fix not created mx6 section
...@@ -30,7 +30,7 @@ def get_job_env_variables( ...@@ -30,7 +30,7 @@ def get_job_env_variables(
env_file: name of the GitLab dotenv file to read variables from env_file: name of the GitLab dotenv file to read variables from
Returns: Returns:
Dictionary of variables with 'name' and 'value' fields Dictionary of variables with 'name' and an set of 'value' fields
""" """
variables = {} variables = {}
...@@ -52,7 +52,11 @@ def get_job_env_variables( ...@@ -52,7 +52,11 @@ def get_job_env_variables(
for line in lines: for line in lines:
name, value = line.partition("=")[::2] name, value = line.partition("=")[::2]
value = value.strip("'\" ") value = value.strip("'\" ")
variables[name] = value if name not in variables.keys():
variables[name] = set()
for elem in value.split(" "):
if len(elem) > 0:
variables[name].add(elem)
return variables return variables
...@@ -94,24 +98,26 @@ def get_pipeline_variable_value(variables: ProjectPipelineVariableManager, key: ...@@ -94,24 +98,26 @@ def get_pipeline_variable_value(variables: ProjectPipelineVariableManager, key:
return variable.value return variable.value
def merge_variables(first: dict[str, str], second: dict[str, str]) -> dict[str, str]: def merge_variables(
"""Merge two dictionaries of variables. If a variable exists in both dictionaries first: dict[str, set[str]], second: dict[str, set[str]]
and one value is not already contained in the other, concatenate its values with ) -> dict[str, set[str]]:
a space in between. """Merge two dictionaries of variables, each variable stored as set.
If a variable exists in both dictionaries the values are merged into one
without duplicates.
Args: Args:
first: a dictionary containing variables first: a dictionary containing variables
secondary: a dictionary containing variables second: a dictionary containing variables
Returns: Returns:
A dictionary containing merged variables A dictionary containing merged variables
""" """
merged = first merged = first
for key in second: for key, value in second.items():
if key not in first or first[key] in second[key]: if key not in first:
merged[key] = second[key] merged[key] = value
elif second[key] not in first[key]: else:
merged[key] = f"{first[key]} {second[key]}" merged[key] |= value
return merged return merged
...@@ -169,6 +175,10 @@ def main(): ...@@ -169,6 +175,10 @@ def main():
) )
# Get all parallel child pipelines with the same Confluence configuration # Get all parallel child pipelines with the same Confluence configuration
# For example the yocto build pipeline and the sdk pipeline should end up
# and the same confluence page, so both need to be found
# To find it, go up on level in the pipeline hierarchy and search child pipelines
# with the same confluence destination
pipelines = [] pipelines = []
parent_pipeline = get_parent_pipeline(project, pipeline) parent_pipeline = get_parent_pipeline(project, pipeline)
if parent_pipeline: if parent_pipeline:
...@@ -241,7 +251,7 @@ def main(): ...@@ -241,7 +251,7 @@ def main():
# Print all variables in a shell compatible form # Print all variables in a shell compatible form
for k, v in sorted(variables.items()): for k, v in sorted(variables.items()):
print(f'{k}="{v}"') print(f'{k}="{" ".join(v)}"')
if __name__ == "__main__": if __name__ == "__main__":
......
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