Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
otb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
Julien Cabieces
otb
Commits
dbf88cdf
Commit
dbf88cdf
authored
5 years ago
by
Antoine Regimbeau
Browse files
Options
Downloads
Plain Diff
Merge branch 'ci_single_token' into 'develop'
CI Use single token for API See merge request
orfeotoolbox/otb!486
parents
d9262230
58022007
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitlab-ci.yml
+1
-1
1 addition, 1 deletion
.gitlab-ci.yml
CI/check_twin_pipelines.py
+9
-5
9 additions, 5 deletions
CI/check_twin_pipelines.py
with
10 additions
and
6 deletions
.gitlab-ci.yml
+
1
−
1
View file @
dbf88cdf
...
...
@@ -27,7 +27,7 @@ before_script:
-
git checkout -f -q $CI_COMMIT_SHA
after_script
:
-
python3 CI/cdash_handler.py $CI_COMMIT_SHA $CI_PROJECT_ID $CI_PROJECT_DIR $K8S_SECRET_
CDASH
-
python3 CI/cdash_handler.py $CI_COMMIT_SHA $CI_PROJECT_ID $CI_PROJECT_DIR $K8S_SECRET_
API_TOKEN
stages
:
-
precheck
...
...
This diff is collapsed.
Click to expand it.
CI/check_twin_pipelines.py
+
9
−
5
View file @
dbf88cdf
...
...
@@ -64,25 +64,29 @@ if __name__ == "__main__":
sha1
=
env
[
'
CI_COMMIT_SHA
'
]
# are we in a merge_request pipeline ?
if
'
CI_MERGE_REQUEST_IID
'
in
env
.
keys
():
if
not
CheckEnvParameters
([
'
K8S_SECRET_TWIN_PIPELINE
'
,
'
CI_PROJECT_ID
'
,
'
CI_PIPELINE_ID
'
]):
if
not
CheckEnvParameters
([
'
K8S_SECRET_API_TOKEN
'
]):
print
(
"
Make sure you have set a valid acces token for Gitlab API
"
)
print
(
"
The K8S_SECRET_API_TOKEN environment variable should be set in
'
Settings -> CI/CD -> Variables
'"
)
sys
.
exit
(
1
)
mrInfo
=
GitlabRequest
(
'
merge_requests/
'
+
env
[
'
CI_MERGE_REQUEST_IID
'
],
token
=
env
[
'
K8S_SECRET_TWIN_PIPELINE
'
])
if
not
CheckEnvParameters
([
'
CI_PROJECT_ID
'
,
'
CI_PIPELINE_ID
'
]):
sys
.
exit
(
1
)
mrInfo
=
GitlabRequest
(
'
merge_requests/
'
+
env
[
'
CI_MERGE_REQUEST_IID
'
],
token
=
env
[
'
K8S_SECRET_API_TOKEN
'
])
wip_regex
=
re
.
compile
(
"
^[Ww][Ii][Pp]:
"
)
# is it a "WIP" merge request ?
if
wip_regex
.
search
(
mrInfo
[
"
title
"
]):
# Yes: cancel the current pipeline
print
(
"
Cancel current pipeline
"
+
env
[
'
CI_PIPELINE_ID
'
])
GitlabRequest
(
'
pipelines/
'
+
env
[
'
CI_PIPELINE_ID
'
]
+
'
/cancel
'
,
data
=
{},
\
project
=
env
[
'
CI_PROJECT_ID
'
],
token
=
env
[
'
K8S_SECRET_
TWIN_PIPELINE
'
])
project
=
env
[
'
CI_PROJECT_ID
'
],
token
=
env
[
'
K8S_SECRET_
API_TOKEN
'
])
time
.
sleep
(
180
)
print
(
"
Error: this pipeline should have been canceled
"
)
sys
.
exit
(
1
)
else
:
# No: cancel any previous "normal" pipeline on the same SHA1
jres
=
GitlabRequest
(
'
pipelines?sha=
'
+
sha1
,
project
=
env
[
'
CI_PROJECT_ID
'
],
token
=
env
[
'
K8S_SECRET_
TWIN_PIPELINE
'
])
jres
=
GitlabRequest
(
'
pipelines?sha=
'
+
sha1
,
project
=
env
[
'
CI_PROJECT_ID
'
],
token
=
env
[
'
K8S_SECRET_
API_TOKEN
'
])
for
item
in
jres
:
if
item
[
"
id
"
]
<
int
(
env
[
'
CI_PIPELINE_ID
'
])
and
item
[
"
status
"
]
==
"
running
"
:
print
(
"
Cancel pipeline
"
+
str
(
item
[
"
id
"
]))
jres2
=
GitlabRequest
(
'
pipelines/
'
+
str
(
item
[
"
id
"
])
+
'
/cancel
'
,
data
=
{},
\
project
=
env
[
'
CI_PROJECT_ID
'
],
token
=
env
[
'
K8S_SECRET_
TWIN_PIPELINE
'
])
project
=
env
[
'
CI_PROJECT_ID
'
],
token
=
env
[
'
K8S_SECRET_
API_TOKEN
'
])
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment