Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.admin
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
bob
bob.admin
Commits
ef3b6ec1
Commit
ef3b6ec1
authored
8 years ago
by
Amir Mohammadi
Browse files
Options
Downloads
Patches
Plain Diff
Add a script that can work as nightlies
parent
711174cd
No related branches found
No related tags found
1 merge request
!26
Add a script that can work as nightlies
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
nightlies/trigger_pipelines.py
+118
-0
118 additions, 0 deletions
nightlies/trigger_pipelines.py
with
118 additions
and
0 deletions
nightlies/trigger_pipelines.py
0 → 100755
+
118
−
0
View file @
ef3b6ec1
#!/usr/bin/env python
"""
Trigger Pipelines.
You need to set the environment variable of
GITLAB_API_TOKEN to your private token
Usage:
{0} <project_name>...
{0} -h | --help
{0} --version
Options:
-h --help Show this screen.
--version Show version.
"""
import
os
import
sys
import
subprocess
import
json
import
time
from
docopt
import
docopt
PACKAGES_ID
=
{
'
bob.extension
'
:
'
1475
'
,
'
bob.blitz
'
:
'
1390
'
,
'
bob.core
'
:
'
1394
'
,
'
bob.ip.draw
'
:
'
1491
'
,
'
bob.io.base
'
:
'
1479
'
,
'
bob.sp
'
:
'
1527
'
,
'
bob.math
'
:
'
1540
'
,
'
bob.ap
'
:
'
1377
'
,
'
bob.measure
'
:
'
1521
'
,
'
bob.db.base
'
:
'
1409
'
,
'
bob.io.image
'
:
'
1481
'
,
'
bob.io.video
'
:
'
1485
'
,
'
bob.io.matlab
'
:
'
1483
'
,
'
bob.ip.base
'
:
'
1487
'
,
'
bob.ip.color
'
:
'
1488
'
,
'
bob.ip.gabor
'
:
'
1497
'
,
'
bob.learn.activation
'
:
'
1506
'
,
'
bob.learn.libsvm
'
:
'
1512
'
,
'
bob.learn.boosting
'
:
'
1509
'
,
'
bob.io.audio
'
:
'
1477
'
,
'
bob.learn.linear
'
:
'
1514
'
,
'
bob.learn.mlp
'
:
'
1517
'
,
'
bob.db.wine
'
:
'
1468
'
,
'
bob.db.mnist
'
:
'
1440
'
,
'
bob.db.atnt
'
:
'
1399
'
,
'
bob.ip.flandmark
'
:
'
1495
'
,
'
bob.ip.facedetect
'
:
'
1493
'
,
'
bob.ip.optflow.hornschunck
'
:
'
1500
'
,
'
bob.ip.optflow.liu
'
:
'
1503
'
,
'
bob.learn.em
'
:
'
1510
'
,
'
bob.db.iris
'
:
'
1431
'
,
}
class
Gitlab
(
object
):
"""
A class that wraps Gitlab API using curl
"""
def
__init__
(
self
,
token
):
super
(
Gitlab
,
self
).
__init__
()
self
.
token
=
token
self
.
base_url
=
'
https://gitlab.idiap.ch/api/v3/
'
def
get_project
(
self
,
project_name
,
namespace
=
'
bob
'
):
cmd
=
[
"
curl
"
,
"
--header
"
,
"
PRIVATE-TOKEN: {}
"
.
format
(
self
.
token
),
self
.
base_url
+
"
projects/{}%2F{}
"
.
format
(
namespace
,
project_name
)]
pipeline
=
subprocess
.
check_output
(
cmd
)
return
json
.
loads
(
pipeline
.
decode
())
def
create_pipeline
(
self
,
project_id
):
cmd
=
[
"
curl
"
,
"
--request
"
,
"
POST
"
,
"
--header
"
,
"
PRIVATE-TOKEN: {}
"
.
format
(
self
.
token
),
self
.
base_url
+
"
projects/{}/pipeline?ref=master
"
.
format
(
project_id
)]
pipeline
=
subprocess
.
check_output
(
cmd
)
return
json
.
loads
(
pipeline
.
decode
())
def
get_pipeline
(
self
,
project_id
,
pipeline_id
):
cmd
=
[
"
curl
"
,
"
--header
"
,
"
PRIVATE-TOKEN: {}
"
.
format
(
self
.
token
),
self
.
base_url
+
"
projects/{}/pipelines/{}
"
.
format
(
project_id
,
pipeline_id
)]
pipeline
=
subprocess
.
check_output
(
cmd
)
return
json
.
loads
(
pipeline
.
decode
())
def
main
(
packages_list
):
gitlab
=
Gitlab
(
os
.
environ
.
get
(
'
GITLAB_API_TOKEN
'
))
for
package
in
packages_list
:
pid
=
PACKAGES_ID
.
get
(
package
)
if
pid
is
None
:
pid
=
gitlab
.
get_project
(
package
)[
'
id
'
]
print
(
'
Triggering a pipeline for {}
'
.
format
(
package
))
last_pipeline
=
gitlab
.
create_pipeline
(
pid
)
while
last_pipeline
[
'
status
'
]
in
[
'
pending
'
,
'
running
'
]:
print
(
'
Pipeline {} for project {} is not finished.
'
'
Sleeping for 30 seconds.
'
.
format
(
last_pipeline
[
'
id
'
],
package
))
time
.
sleep
(
30
)
last_pipeline
=
gitlab
.
get_pipeline
(
pid
,
last_pipeline
[
'
id
'
])
if
not
last_pipeline
[
'
status
'
]
==
'
passed
'
:
print
(
'
Pipeline {} for project {} failed. Exiting ...
'
.
format
(
last_pipeline
[
'
id
'
],
package
))
return
if
__name__
==
'
__main__
'
:
arguments
=
docopt
(
__doc__
.
format
(
sys
.
argv
[
0
]),
version
=
'
Nightlies 0.0.1
'
)
print
(
arguments
)
main
(
arguments
[
'
<project_name>
'
])
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