-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
93 lines (79 loc) · 3.65 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
elifePipeline {
node('containers-jenkins-plugin') {
def image_repo = 'elifesciences/data-science-dags'
def commit
def commitShort
def branch
def timestamp
def git_url
stage 'Checkout', {
checkout scm
commit = elifeGitRevision()
commitShort = elifeGitRevision().substring(0, 8)
branch = sh(script: 'git rev-parse --abbrev-ref HEAD', returnStdout: true).trim()
timestamp = sh(script: 'date --utc +%Y%m%d.%H%M', returnStdout: true).trim()
git_url = getGitUrl()
}
stage 'Build and run tests', {
// Note: we are using staging source dataset in ci
// because some source tables or views may not be present in ci
withDataPipelineGcpCredentials {
try {
timeout(time: 30, unit: 'MINUTES') {
sh "make IMAGE_TAG=${commit} REVISION=${commit} \
DATA_SCIENCE_SOURCE_DATASET=staging \
DATA_SCIENCE_OUTPUT_DATASET=ci \
ci-build-and-test"
}
} finally {
sh "docker-compose logs"
sh "make ci-clean"
}
}
}
stage 'Build main image', {
sh "make IMAGE_REPO=${image_repo} IMAGE_TAG=${commit} ci-build-main-image"
}
elifeMainlineOnly {
def dev_image_repo = image_repo + '_unstable'
stage 'Push image', {
sh "make EXISTING_IMAGE_TAG=${commit} EXISTING_IMAGE_REPO=${image_repo} IMAGE_TAG=${commit} IMAGE_REPO=${dev_image_repo} retag-push-image"
sh "make EXISTING_IMAGE_TAG=${commit} EXISTING_IMAGE_REPO=${image_repo} IMAGE_TAG=${branch}-${commitShort}-${timestamp} IMAGE_REPO=${dev_image_repo} retag-push-image"
sh "make EXISTING_IMAGE_TAG=${commit} EXISTING_IMAGE_REPO=${image_repo} IMAGE_TAG=latest IMAGE_REPO=${dev_image_repo} retag-push-image"
}
stage 'Push unstable image for PeerScout API', {
def image = DockerImage.elifesciences(this, 'data-science-dags_peerscout-api', commit)
def unstable_image = image.addSuffixAndTag('_unstable', commit)
unstable_image.tag('latest').push()
unstable_image.tag("${branch}-${commitShort}-${timestamp}").push()
unstable_image.push()
}
stage 'Merge to master', {
elifeGitMoveToBranch commit, 'master'
}
}
elifeTagOnly { tagName ->
def candidateVersion = tagName - "v"
stage 'Push release image', {
sh "make EXISTING_IMAGE_TAG=${commit} EXISTING_IMAGE_REPO=${image_repo} IMAGE_TAG=latest IMAGE_REPO=${image_repo} retag-push-image"
sh "make EXISTING_IMAGE_TAG=${commit} EXISTING_IMAGE_REPO=${image_repo} IMAGE_TAG=${candidateVersion} IMAGE_REPO=${image_repo} retag-push-image"
}
stage 'Push release image for PeerScout API', {
def image = DockerImage.elifesciences(this, 'data-science-dags_peerscout-api', commit)
image.tag('latest').push()
image.tag(candidateVersion).push()
}
}
}
}
def withDataPipelineGcpCredentials(doSomething) {
try {
sh 'vault.sh kv get -field credentials secret/containers/data-pipeline/gcp > credentials.json'
doSomething()
} finally {
sh 'echo > credentials.json'
}
}
def getGitUrl() {
return sh(script: "git config --get remote.origin.url", returnStdout: true).trim()
}