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(
env_file: name of the GitLab dotenv file to read variables from
Returns:
Dictionary of variables with 'name' and 'value' fields
Dictionary of variables with 'name' and an set of 'value' fields
"""
variables = {}
......@@ -52,7 +52,11 @@ def get_job_env_variables(
for line in lines:
name, value = line.partition("=")[::2]
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
......@@ -94,24 +98,26 @@ def get_pipeline_variable_value(variables: ProjectPipelineVariableManager, key:
return variable.value
def merge_variables(first: dict[str, str], second: dict[str, str]) -> dict[str, str]:
"""Merge two dictionaries of variables. If a variable exists in both dictionaries
and one value is not already contained in the other, concatenate its values with
a space in between.
def merge_variables(
first: dict[str, set[str]], second: dict[str, set[str]]
) -> dict[str, set[str]]:
"""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:
first: a dictionary containing variables
secondary: a dictionary containing variables
second: a dictionary containing variables
Returns:
A dictionary containing merged variables
"""
merged = first
for key in second:
if key not in first or first[key] in second[key]:
merged[key] = second[key]
elif second[key] not in first[key]:
merged[key] = f"{first[key]} {second[key]}"
for key, value in second.items():
if key not in first:
merged[key] = value
else:
merged[key] |= value
return merged
......@@ -169,6 +175,10 @@ def main():
)
# 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 = []
parent_pipeline = get_parent_pipeline(project, pipeline)
if parent_pipeline:
......@@ -241,7 +251,7 @@ def main():
# Print all variables in a shell compatible form
for k, v in sorted(variables.items()):
print(f'{k}="{v}"')
print(f'{k}="{" ".join(v)}"')
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