Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hpc-factory
Manage
Activity
Members
Labels
Plan
Issues
74
Issue boards
Milestones
Wiki
Code
Merge requests
11
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rc
hpc-factory
Merge requests
!196
Feat gl cicd var scripts
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Feat gl cicd var scripts
atlurie/hpc-factory:feat-gl-cicd-var-scripts
into
main
Overview
0
Commits
18
Pipelines
0
Changes
4
Merged
Eesaan Atluri
requested to merge
atlurie/hpc-factory:feat-gl-cicd-var-scripts
into
main
1 month ago
Overview
0
Commits
18
Pipelines
0
Changes
1
Expand
Closes
#232 (closed)
Edited
1 month ago
by
Eesaan Atluri
👍
1
👎
0
Merge request reports
Compare
version 7
version 15
ab16498c
1 month ago
version 14
33258466
1 month ago
version 13
190a409a
1 month ago
version 12
329bd6ec
1 month ago
version 11
a55c7988
1 month ago
version 10
abb37287
1 month ago
version 9
a836c052
1 month ago
version 8
d0b08275
1 month ago
version 7
243902b6
1 month ago
version 6
cb6e01a9
1 month ago
version 5
8d121964
1 month ago
version 4
ef30db8f
1 month ago
version 3
05fc1163
1 month ago
version 2
1f33598a
1 month ago
version 1
fac0002a
1 month ago
main (base)
and
version 8
latest version
0d34d327
18 commits,
1 month ago
version 15
ab16498c
19 commits,
1 month ago
version 14
33258466
22 commits,
1 month ago
version 13
190a409a
21 commits,
1 month ago
version 12
329bd6ec
20 commits,
1 month ago
version 11
a55c7988
20 commits,
1 month ago
version 10
abb37287
19 commits,
1 month ago
version 9
a836c052
18 commits,
1 month ago
version 8
d0b08275
16 commits,
1 month ago
version 7
243902b6
10 commits,
1 month ago
version 6
cb6e01a9
9 commits,
1 month ago
version 5
8d121964
8 commits,
1 month ago
version 4
ef30db8f
7 commits,
1 month ago
version 3
05fc1163
6 commits,
1 month ago
version 2
1f33598a
5 commits,
1 month ago
version 1
fac0002a
4 commits,
1 month ago
Show latest version
1 file
+
34
−
16
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
scripts/gitlab-ci-vars-updater.py
+
34
−
16
Options
@@ -15,32 +15,51 @@ def load_file(file_path):
# Function to create or update a GitLab CI/CD variable
def
create_or_update_variable
(
project
,
var_dict
):
# Check if the variable exists in the project
key
=
var_dict
.
get
(
"
key
"
)
scope
=
var_dict
.
get
(
"
environment_scope
"
,
"
*
"
)
p_variable
=
None
DEFAULTS
=
{
"
variable_type
"
:
"
env_var
"
,
"
hidden
"
:
False
,
"
protected
"
:
False
,
"
masked
"
:
False
,
"
environment_scope
"
:
"
*
"
,
"
raw
"
:
False
,
"
description
"
:
None
,
}
# Merge defaults with var_dict
var_dict
=
{
**
DEFAULTS
,
**
var_dict
}
# Fetch a variable with matching key and scope
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
break
except
gitlab
.
exceptions
.
GitlabGetError
:
print
(
"
Variable not found
"
)
p_variable
=
False
if
p_variable
:
if
p_variable
!=
var_dict
:
# Check if the attributes are the same
for
k
,
v
in
var_dict
.
items
()
:
if
p_variable
[
k
]
!=
v
:
# If not update the value in the project
print
(
f
"
Updating key
{
k
}
value
"
)
project
.
variables
.
upd
ate
(
k
,
{
"
value
"
:
v
}
)
exit
(
1
)
# Check if the variable exists and same as input
if
p_variable
is
not
None
:
if
p_variable
.
asdict
()
!=
var_dict
:
# if not same update the project variable
print
(
f
"
Updating
{
p_variable
.
attributes
[
'
key
'
]
}
"
)
p_variable
.
delete
(
)
return
project
.
variables
.
cre
ate
(
var_dict
)
else
:
print
(
f
"
variable
{
var_dict
[
"
key
"
]
}
already exists
"
)
# Create variable if it doesn't exist in the project
else
:
for
k
,
v
in
var_dict
.
items
():
print
(
f
"
Creating variable
{
var_dict
[
"
key
"
]
}
"
)
return
project
.
variables
.
create
(
var_dict
)
print
(
f
"
Creating variable
{
var_dict
[
"
key
"
]
}
"
)
return
project
.
variables
.
create
(
var_dict
)
def
get_pipeline_vars_by_key
(
sched_pipeline
,
key_name
):
p_vars
=
sched_pipeline
.
attributes
[
"
variables
"
]
# p_vars.sort(key=lambda x: x["key"])
for
p_variable
in
p_vars
:
if
p_variable
.
get
(
"
key
"
)
==
key_name
:
return
p_variable
@@ -104,7 +123,6 @@ def main():
# Load the CI vars file
var_list
=
load_file
(
args
.
var_file
)
# var_list.sort(key=lambda x: x["key"])
# Create or update all variables
for
var_dict
in
var_list
:
Loading