Skip to content
Snippets Groups Projects

Feat gl cicd var scripts

Merged Eesaan Atluri requested to merge atlurie/hpc-factory:feat-gl-cicd-var-scripts into main
1 file
+ 23
3
Compare changes
  • Side-by-side
  • Inline
@@ -15,12 +15,19 @@ def load_file(file_path):
# Function to create or update a GitLab CI/CD variable
def create_or_update_variable(project, var_dict):
key = var_dict.get("key")
scope = var_dict.get("environment_scope", "*")
p_variable = None
# Check if the variable exists in the project
try:
p_variable = project.variables.get(var_dict["key"]).asdict()
all_vars = project.variables.list(get_all=True)
for var in all_vars:
if var.key == key and var.environment_scope == scope:
p_variable = var.asdict()
break
except gitlab.exceptions.GitlabGetError:
print("Variable not found")
p_variable = False
exit(1)
if p_variable:
if p_variable != var_dict:
# Check if the attributes are the same
@@ -28,7 +35,20 @@ def create_or_update_variable(project, var_dict):
if p_variable[k] != v:
# If not update the value in the project
print(f"Updating key {k} value")
project.variables.update(k, {"value": v})
# project.variables.update(k, {"value": v})
project.variables.update(
key,
{
"value": var_dict["value"],
"environment_scope": scope,
"variable_type": var_dict.get("variable_type", "env_var"),
"masked": var_dict.get("masked", False),
"protected": var_dict.get("protected", False),
"raw": var_dict.get("raw", False),
"description": var_dict.get("description", None),
},
)
break
else:
print(f"variable {var_dict["key"]} already exists")
# Create variable if it doesn't exist in the project
Loading