Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dumux
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
dumux-repositories
dumux
Commits
894839f3
Commit
894839f3
authored
3 years ago
by
Dennis Gläser
Browse files
Options
Downloads
Patches
Plain Diff
[ci] add script to get info on prior pipeline
parent
f950c025
No related branches found
No related tags found
1 merge request
!2644
Feature/continuous master pipeline status
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
.gitlab-ci/getpipelineinfo.py
+73
-0
73 additions, 0 deletions
.gitlab-ci/getpipelineinfo.py
with
73 additions
and
0 deletions
.gitlab-ci/getpipelineinfo.py
0 → 100644
+
73
−
0
View file @
894839f3
import
json
import
sys
import
os
from
argparse
import
ArgumentParser
try
:
path
=
os
.
path
.
split
(
os
.
path
.
abspath
(
__file__
))[
0
]
sys
.
path
.
append
(
os
.
path
.
join
(
path
,
'
../bin/util
'
))
from
common
import
runCommand
except
Exception
:
sys
.
exit
(
'
Could not import common module
'
)
def
findPipeline
(
pipelineFile
,
predicate
):
with
open
(
pipelineFile
)
as
pipeLines
:
for
pipeLine
in
json
.
load
(
pipeLines
):
if
predicate
(
pipeLine
):
return
pipeLine
return
None
parser
=
ArgumentParser
(
description
=
'
Find and print information on a previously run pipeline
'
)
parser
.
add_argument
(
'
-s
'
,
'
--status
'
,
required
=
False
,
default
=
'
success
'
,
help
=
'
Define the status of the pipeline to be found
'
)
parser
.
add_argument
(
'
-p
'
,
'
--print-format
'
,
required
=
True
,
choices
=
[
'
pipeline-id
'
,
'
commit-sha
'
],
help
=
'
Switch between reporting the pipeline-id/commit-sha
'
)
parser
.
add_argument
(
'
-l
'
,
'
--look-for
'
,
required
=
True
,
choices
=
[
'
latest
'
,
'
HEAD
'
],
help
=
'
Define how to search for pipelines
'
)
parser
.
add_argument
(
'
-f
'
,
'
--status-file
'
,
required
=
True
,
help
=
'
The .json file with the latest pipeline statuses
'
)
args
=
vars
(
parser
.
parse_args
())
currentBranch
=
runCommand
(
'
git branch --show-current
'
).
strip
(
'
\n
'
)
currentCommitInfo
=
runCommand
(
'
git show HEAD
'
).
split
(
'
\n
'
)
headIsMergeCommit
=
'
Merge:
'
in
currentCommitInfo
[
1
]
headSHA
=
runCommand
(
'
git rev-list HEAD --max-count=1
'
).
strip
(
'
\n
'
)
if
headIsMergeCommit
:
preSHA
=
runCommand
(
'
git rev-list HEAD --max-count=2
'
).
split
(
'
\n
'
)[
1
]
mrSha
=
currentCommitInfo
[
1
].
split
()[
2
]
def
checkCommitSHA
(
pipeLine
):
sha
=
pipeLine
[
'
sha
'
]
if
headIsMergeCommit
:
return
sha
==
headSHA
or
sha
==
preSHA
or
mrSha
in
sha
return
sha
==
headSHA
def
checkStatus
(
pipeLine
):
return
pipeLine
[
'
status
'
]
==
args
[
'
status
'
]
def
checkBranch
(
pipeLine
):
return
pipeLine
[
'
ref
'
]
==
currentBranch
def
find
(
predicate
):
return
findPipeline
(
args
[
'
status_file
'
],
predicate
)
if
args
[
'
look_for
'
]
==
'
HEAD
'
:
pipeLine
=
find
(
lambda
p
:
checkStatus
(
p
)
and
checkCommitSHA
(
p
))
elif
args
[
'
look_for
'
]
==
'
latest
'
:
pipeLine
=
find
(
lambda
p
:
checkStatus
(
p
)
and
checkBranch
(
p
))
if
pipeLine
is
not
None
:
if
args
[
'
print_format
'
]
==
'
pipeline-id
'
:
print
(
pipeLine
[
'
id
'
])
elif
args
[
'
print_format
'
]
==
'
commit-sha
'
:
print
(
pipeLine
[
'
sha
'
])
else
:
sys
.
exit
(
'
Could not find a succesful pipeline
'
)
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