-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
76 lines (65 loc) · 2.8 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
elifePipeline {
node('containers-jenkins-plugin') {
def image_repo = 'elifesciences/peerscout-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', {
withDataPipelineGcpCredentials {
try {
timeout(time: 30, unit: 'MINUTES') {
sh "make ci-build-dev"
sh "GOOGLE_APPLICATION_CREDENTIALS=./credentials.json \
make ci-test-including-end2end"
}
} finally {
sh "docker-compose ps"
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 'Merge to master', {
elifeGitMoveToBranch commit, 'master'
}
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"
}
}
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"
}
}
}
}
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()
}