This repository has been archived by the owner on Mar 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathJenkinsfile
107 lines (94 loc) · 3.68 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import groovy.json.JsonSlurper
@NonCPS
def jsonToPypirc(String jsonText, String sectionName) {
def credentials = new JsonSlurper().parseText(jsonText)
echo "Username: ${credentials.username}"
return "[${sectionName}]\nusername: ${credentials.username}\npassword: ${credentials.password}"
}
def withPypiCredentials(String env, String sectionName, doSomething) {
try {
writeFile(file: '.pypirc', text: jsonToPypirc(sh(
script: "vault.sh kv get -format=json secret/containers/pypi/${env} | jq .data.data",
returnStdout: true
).trim(), sectionName))
doSomething()
} finally {
sh 'echo > .pypirc'
}
}
elifePipeline {
node('containers-jenkins-plugin') {
def commit
def version
stage 'Checkout', {
checkout scm
commit = elifeGitRevision()
if (env.TAG_NAME) {
version = env.TAG_NAME - 'v'
} else {
version = 'develop'
}
}
stage 'Build and run tests', {
try {
withCommitStatus({
sh "make IMAGE_TAG=${commit} REVISION=${commit} ci-build-all"
}, 'ci-build-all', commit)
withCommitStatus({
sh "make IMAGE_TAG=${commit} REVISION=${commit} ci-lint"
}, 'ci-lint', commit)
withCommitStatus({
sh "make IMAGE_TAG=${commit} REVISION=${commit} ci-pytest"
}, 'ci-pytest', commit)
withCommitStatus({
sh "make IMAGE_TAG=${commit} REVISION=${commit} ci-end-to-end"
}, 'ci-end-to-end', commit)
} finally {
sh "make ci-clean"
}
}
elifeMainlineOnly {
stage 'Merge to master', {
elifeGitMoveToBranch commit, 'master'
}
stage 'Push unstable sciencebeam-parser image', {
def image = DockerImage.elifesciences(this, 'sciencebeam-parser', commit)
def unstable_image = image.addSuffixAndTag('_unstable', commit)
unstable_image.tag('latest').push()
unstable_image.push()
}
stage 'Push unstable sciencebeam-parser cv image', {
def tag = "${commit}-cv"
def image = DockerImage.elifesciences(this, 'sciencebeam-parser', tag)
def unstable_image = image.addSuffixAndTag('_unstable', tag)
unstable_image.tag('latest-cv').push()
unstable_image.push()
}
}
elifePullRequestOnly { prNumber ->
stage 'Push package to test.pypi.org', {
withPypiCredentials 'staging', 'testpypi', {
sh "make IMAGE_TAG=${commit} REVISION=${commit} ci-push-testpypi"
}
}
}
elifeTagOnly { repoTag ->
stage 'Push stable sciencebeam-parser image', {
def image = DockerImage.elifesciences(this, 'sciencebeam-parser', commit)
image.tag('latest').push()
image.tag(version).push()
}
stage 'Push stable sciencebeam-parser cv image', {
def tag = "${commit}-cv"
def image = DockerImage.elifesciences(this, 'sciencebeam-parser', tag)
image.tag('latest-cv').push()
image.tag("${version}-cv").push()
}
stage 'Push package to pypi', {
withPypiCredentials 'prod', 'pypi', {
sh "make IMAGE_TAG=${commit} VERSION=${version} NO_BUILD=y ci-push-pypi"
}
}
}
}
}