forked from molgenis/molgenis-service-armadillo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
140 lines (140 loc) · 6.46 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
pipeline {
agent {
kubernetes {
inheritFrom 'molgenis-jdk11'
}
}
environment {
REPOSITORY = 'molgenis/armadillo'
LOCAL_REPOSITORY = "${LOCAL_REGISTRY}/${REPOSITORY}"
CHART_VERSION = '0.12.2'
TIMESTAMP = sh(returnStdout: true, script: "date -u +'%F_%H-%M-%S'").trim()
}
stages {
stage('Prepare') {
steps {
script {
env.GIT_COMMIT = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
}
container('vault') {
script {
sh "mkdir ${JENKINS_AGENT_WORKDIR}/.rancher"
sh "mkdir ${JENKINS_AGENT_WORKDIR}/.m2"
sh(script: "vault read -field=value secret/ops/jenkins/rancher/cli2.json > ${JENKINS_AGENT_WORKDIR}/.rancher/cli2.json")
sh(script: "vault read -field=value secret/ops/jenkins/maven/settings.xml > ${JENKINS_AGENT_WORKDIR}/.m2/settings.xml")
env.GITHUB_TOKEN = sh(script: "vault read -field=value secret/ops/token/github", returnStdout: true)
env.SONAR_TOKEN = sh(script: 'vault read -field=value secret/ops/token/sonar', returnStdout: true)
env.GITHUB_USER = sh(script: 'vault read -field=username secret/ops/token/github', returnStdout: true)
}
}
dir("${JENKINS_AGENT_WORKDIR}/.m2") {
stash includes: 'settings.xml', name: 'maven-settings'
}
dir("${JENKINS_AGENT_WORKDIR}/.rancher") {
stash includes: 'cli2.json', name: 'rancher-config'
}
}
}
stage('Steps [ PR ]') {
when {
changeRequest()
}
environment {
// PR-1234-231
TAG = "PR-${CHANGE_ID}-${BUILD_NUMBER}"
}
stages {
stage('Build [ PR ]') {
steps {
container('maven') {
script {
env.PREVIEW_VERSION = sh(script: "grep version pom.xml | grep SNAPSHOT | cut -d'>' -f2 | cut -d'<' -f1", returnStdout: true).trim() + "-${env.TAG}"
}
sh "mvn -q -B versions:set -DnewVersion=${PREVIEW_VERSION} -DgenerateBackupPoms=false"
sh "mvn -q -B clean install -Dmaven.test.redirectTestOutputToFile=true"
// Fetch the target branch, sonar likes to take a look at it
sh "git fetch --no-tags origin ${CHANGE_TARGET}:refs/remotes/origin/${CHANGE_TARGET}"
sh "mvn -q -B sonar:sonar -Dsonar.login=${env.SONAR_TOKEN} -Dsonar.github.oauth=${env.GITHUB_TOKEN} -Dsonar.pullrequest.base=${CHANGE_TARGET} -Dsonar.pullrequest.branch=${BRANCH_NAME} -Dsonar.pullrequest.key=${env.CHANGE_ID} -Dsonar.pullrequest.provider=GitHub -Dsonar.pullrequest.github.repository=molgenis/molgenis-service-armadillo -Dsonar.ws.timeout=120"
}
}
post {
always {
junit '**/target/surefire-reports/**.xml'
}
}
}
stage('Push to registries [ PR ]') {
steps {
container('maven') {
dir('armadillo') {
script {
sh "mvn -q -B jib:build -Ddockerfile.tag=${TAG} -Ddockerfile.repository=${LOCAL_REPOSITORY}"
}
}
}
}
}
}
}
stage('Steps [ master ]') {
when {
branch 'master'
}
environment {
TAG = "dev-${TIMESTAMP}"
}
stages {
stage('Build [ master ]') {
steps {
container('maven') {
sh "mvn -q -B clean install -Dmaven.test.redirectTestOutputToFile=true -DskipITs"
sh "mvn -q -B sonar:sonar -Dsonar.login=${SONAR_TOKEN} -Dsonar.ws.timeout=120"
}
}
post {
always {
junit '**/target/surefire-reports/**.xml'
}
}
}
stage('Push to registries [ master ]') {
steps {
container('maven') {
dir('armadillo') {
script {
sh "mvn -q -B jib:build -Ddockerfile.tag=${TAG} -Ddockerfile.repository=${LOCAL_REPOSITORY}"
sh "mvn -q -B jib:build -Ddockerfile.tag=dev -Ddockerfile.repository=${LOCAL_REPOSITORY}"
}
}
}
}
}
stage("Deploy to dev [ master ]") {
steps {
milestone(ordinal: 100, label: 'deploy to armadillo.dev.molgenis.org')
container('rancher') {
sh "rancher apps upgrade --set 'server.image.tag=${TAG}' --set 'server.image.repository=${LOCAL_REPOSITORY}' armadillo ${CHART_VERSION}"
}
}
}
stage('Prepare Release [ master ]') {
steps {
timeout(time: 40, unit: 'MINUTES') {
input(message: 'Prepare to release?')
}
container('maven') {
sh "mvn -q -B release:prepare -Dmaven.test.redirectTestOutputToFile=true -Darguments=\"-q -B -Dmaven.test.redirectTestOutputToFile=true\""
}
}
}
stage('Perform release [ master ]') {
steps {
container('maven') {
sh "mvn -q -B release:perform -Darguments=\"-q -B -Dmaven.test.redirectTestOutputToFile=true\""
}
}
}
}
}
}
}