-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile.groovy
99 lines (92 loc) · 3.48 KB
/
Jenkinsfile.groovy
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
dockerRegistry = "ghcr.io"
githubRepo = "icgc-argo/kship"
def commit = "UNKNOWN"
def version = "UNKNOWN"
pipeline {
agent {
kubernetes {
label 'kship-executor'
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: jdk
tty: true
image: openjdk:11-jdk
- name: docker
image: docker:18-git
tty: true
volumeMounts:
- mountPath: /var/run/docker.sock
name: docker-sock
volumes:
- name: docker-sock
hostPath:
path: /var/run/docker.sock
type: File
"""
}
}
stages {
// get the commit and version number for current release
stage('Prepare') {
steps {
script {
commit = sh(returnStdout: true, script: 'git describe --always').trim()
}
script {
version = sh(returnStdout: true, script: "cat ./.mvn/maven.config | grep revision | cut -d '=' -f2").trim()
}
}
}
// run tests and package
stage('Test') {
steps {
container('jdk') {
// remove the snapshot and append the commit (the dot before ${commit} is intentional)
// this does NOT publish to a maven artifacts store
sh "./mvnw -Dsha1=.${commit} -Dchangelist=-${BUILD_NUMBER} test package"
}
}
}
// publish the edge tag
stage('Publish Develop') {
when {
branch "develop"
}
steps {
container('docker') {
withCredentials([usernamePassword(credentialsId:'argoContainers', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh "docker login ${dockerRegistry} -u $USERNAME -p $PASSWORD"
}
// the network=host needed to download dependencies using the host network (since we are inside 'docker'
// container)
sh "docker build --network=host . -t ${dockerRegistry}/${githubRepo}:edge -t ${dockerRegistry}/${githubRepo}:${version}-${commit}"
sh "docker push ${dockerRegistry}/${githubRepo}:${version}-${commit}"
sh "docker push ${dockerRegistry}/${githubRepo}:edge"
}
}
}
stage('Release & Tag') {
when {
branch "master"
}
steps {
container('docker') {
withCredentials([usernamePassword(credentialsId: 'argoGithub', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh "git tag ${version}"
sh "git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/${githubRepo} --tags"
}
withCredentials([usernamePassword(credentialsId:'argoContainers', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh "docker login ${dockerRegistry} -u $USERNAME -p $PASSWORD"
}
// DNS error if --network is default
sh "docker build --network=host . -t ${dockerRegistry}/${githubRepo}:latest -t ${dockerRegistry}/${githubRepo}:${version}"
sh "docker push ${dockerRegistry}/${githubRepo}:${version}"
sh "docker push ${dockerRegistry}/${githubRepo}:latest"
}
}
}
}
}