Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
gitlab-ci
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
3
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
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
SECO Northern Europe
Yocto
infrastructure
gitlab-ci
Commits
1b853463
Commit
1b853463
authored
4 years ago
by
Tim Jaacks
Browse files
Options
Downloads
Patches
Plain Diff
Add error handling to retriggering jobs
parent
8c6cfd50
No related branches found
No related tags found
1 merge request
!28
Add error handling to retriggering jobs
Pipeline
#8143
passed with stage
in 19 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
retrigger_mr_pipeline_job.py
+13
-14
13 additions, 14 deletions
retrigger_mr_pipeline_job.py
retrigger_mr_pipeline_jobs.py
+15
-2
15 additions, 2 deletions
retrigger_mr_pipeline_jobs.py
with
28 additions
and
16 deletions
retrigger_mr_pipeline_job.py
+
13
−
14
View file @
1b853463
...
...
@@ -6,7 +6,7 @@ import sys
from
gitlab
import
Gitlab
,
GitlabGetError
def
retrigger_mr_pipeline_job
(
project
,
mr
,
job_name
):
def
retrigger_mr_pipeline_job
(
project
,
mr
,
job_name
,
status_list
):
# Get pipeline
pipeline
=
project
.
pipelines
.
get
(
mr
.
pipeline
.
get
(
"
id
"
),
retry_transient_errors
=
True
)
...
...
@@ -15,20 +15,19 @@ def retrigger_mr_pipeline_job(project, mr, job_name):
for
pipelinejob
in
pipeline
.
jobs
.
list
():
if
pipelinejob
.
name
==
job_name
:
job
=
project
.
jobs
.
get
(
pipelinejob
.
id
,
retry_transient_errors
=
True
)
if
not
job
:
sys
.
exit
(
"
ERROR: could not find job
'
%s
'
in pipeline of !%s
"
%
(
job_name
,
mr
.
iid
)
)
print
(
"
Could not find job
'
%s
'
in pipeline of !%s
"
%
(
job_name
,
mr
.
iid
))
return
None
# Only retrigger if job is in certain status
if
job
.
status
not
in
status_list
:
return
None
# Retrigger if not already failed
if
job
.
status
not
in
[
"
failed
"
,
"
skipped
"
]:
job
.
retry
()
print
(
"
Retrigger job
'
%s
'
of pipeline #%s:
"
%
(
job_name
,
pipeline
.
id
))
job
=
project
.
jobs
.
get
(
job
.
id
,
retry_transient_errors
=
True
)
print
(
job
.
web_url
)
else
:
job
=
None
# Retrigger job
job
.
retry
()
print
(
"
Retrigger job
'
%s
'
of pipeline #%s:
"
%
(
job_name
,
pipeline
.
id
))
job
=
project
.
jobs
.
get
(
job
.
id
,
retry_transient_errors
=
True
)
print
(
job
.
web_url
)
return
job
...
...
@@ -80,7 +79,7 @@ def main():
if
not
mr
:
sys
.
exit
(
"
ERROR: could not find merge request %s!%s
"
%
(
project
.
name
,
args
.
iid
))
retrigger_mr_pipeline_job
(
project
,
mr
,
args
.
job
)
retrigger_mr_pipeline_job
(
project
,
mr
,
args
.
job
,
[
"
success
"
,
"
running
"
]
)
if
__name__
==
"
__main__
"
:
...
...
This diff is collapsed.
Click to expand it.
retrigger_mr_pipeline_jobs.py
+
15
−
2
View file @
1b853463
...
...
@@ -2,7 +2,8 @@
import
common
import
argparse
from
gitlab
import
Gitlab
import
sys
from
gitlab
import
Gitlab
,
GitlabJobRetryError
from
get_merge_requests
import
get_merge_requests
from
retrigger_mr_pipeline_job
import
retrigger_mr_pipeline_job
...
...
@@ -72,8 +73,20 @@ def main():
commit
=
args
.
commit
,
)
failed
=
0
for
mr
in
mrs
:
retrigger_mr_pipeline_job
(
project
,
mr
,
args
.
job
)
try
:
retrigger_mr_pipeline_job
(
project
,
mr
,
args
.
job
,
[
"
success
"
,
"
running
"
])
except
GitlabJobRetryError
as
e
:
print
(
"
ERROR: Could not retrigger job
'
%s
'
of %s!%s: %s
"
%
(
args
.
job
,
args
.
project
,
mr
.
iid
,
e
)
)
failed
=
failed
+
1
continue
if
failed
>
0
:
sys
.
exit
(
1
)
if
__name__
==
"
__main__
"
:
...
...
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