forked from molgenis/molgenis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
177 lines (177 loc) · 8.56 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
pipeline {
agent {
kubernetes {
inheritFrom 'molgenis-jdk11'
}
}
environment {
LOCAL_REPOSITORY = "${LOCAL_REGISTRY}/molgenis/molgenis-app"
CHART_VERSION = '1.15.2'
TIMESTAMP = sh(returnStdout: true, script: "date -u +'%F_%H-%M-%S'").trim()
}
stages {
stage('Retrieve build secrets') {
steps {
container('vault') {
script {
sh "mkdir ${JENKINS_AGENT_WORKDIR}/.m2"
sh "mkdir ${JENKINS_AGENT_WORKDIR}/.rancher"
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.SONAR_TOKEN = sh(script: 'vault read -field=value secret/ops/token/sonar', returnStdout: true)
env.GITHUB_TOKEN = sh(script: 'vault read -field=value secret/ops/token/github', 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-23
TAG = "PR-${CHANGE_ID}-${BUILD_NUMBER}"
}
stages {
stage('Build, Test, Push to Registries [ PR ]') {
steps {
container('maven') {
script {
// 8.5.0-SNAPSHOT-PR-1234-23
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 -T1C"
sh "mvn -q -B clean deploy -Dmaven.test.redirectTestOutputToFile=true -DskipITs -Djib.tag=${TAG} -Djib.repository=${LOCAL_REPOSITORY} -T1C -DargLine='-XX:TieredStopAtLevel=1 -noverify'"
// 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 -Dsonar.ws.timeout=120 -T1C"
}
}
post {
always {
junit '**/target/surefire-reports/**.xml'
}
}
}
}
}
stage('Steps [ master ]') {
when {
branch 'master'
}
environment {
TAG = "dev-${TIMESTAMP}"
}
stages {
stage('Build, Test, Push to Registries [ master ]') {
steps {
container('maven') {
sh "mvn -q -B clean deploy -Dmaven.test.redirectTestOutputToFile=true -DskipITs -Djib.tag=${TAG} -Djib.repository=${LOCAL_REPOSITORY} -Djib.to.tags=latest"
sh "mvn -q -B sonar:sonar -Dsonar.login=${SONAR_TOKEN} -Dsonar.ws.timeout=120"
}
}
post {
always {
junit '**/target/surefire-reports/**.xml'
}
}
}
stage("Deploy to dev [ master ]") {
steps {
milestone(ordinal: 100, label: 'deploy to master.dev.molgenis.org')
container('rancher') {
sh "rancher apps upgrade --set image.tag=${TAG} master ${CHART_VERSION}"
}
}
}
}
}
stage('Steps [ x.x ]') {
when {
expression { BRANCH_NAME ==~ /[0-9]\.[0-9]/ }
beforeAgent true
}
agent {
kubernetes {
label('molgenis-it-jdk11')
}
}
stages {
stage('Build test and publish [ x.x ]') {
steps {
dir("${JENKINS_AGENT_WORKDIR}/.m2") {
unstash 'maven-settings'
}
container('maven') {
sh "mvn -q -B clean deploy -Dmaven.test.redirectTestOutputToFile=true -DskipITs -Djib.tag=${BRANCH_NAME}-latest"
sh "mvn -q -B sonar:sonar -Dsonar.login=${SONAR_TOKEN} -Dsonar.branch.name=${BRANCH_NAME} -Dsonar.ws.timeout=120"
}
}
}
stage('Prepare Release [ x.x ]') {
steps {
timeout(time: 10, unit: 'MINUTES') {
input(message: 'Prepare to release?')
}
container('maven') {
sh "mvn -q -B verify -pl molgenis-platform-integration-tests -Dmaven.test.redirectTestOutputToFile=true -Dit_db_user=molgenis -Dit_db_password=molgenis -Dit_db_name=molgenis -Delasticsearch.cluster.name=molgenis -Delasticsearch.transport.addresses=localhost:9300 -P!create-it-db -P!create-it-es"
sh "mvn -q -B release:prepare -DskipITs -Dmaven.test.redirectTestOutputToFile=true -Darguments=\"-q -B -DskipITs -Dmaven.test.redirectTestOutputToFile=true -Pproduction\""
script {
env.TAG = sh(script: "grep project.rel release.properties | head -n1 | cut -d'=' -f2", returnStdout: true).trim()
}
}
}
}
stage('Perform release [ x.x ]') {
steps {
container('maven') {
sh "mvn -q -B release:perform -Darguments=\"-q -B -Dwar.deploy.skip=false -DskipITs -Dmaven.test.redirectTestOutputToFile=true -Pproduction\""
}
}
}
stage('Deploy to test [ x.x ]') {
steps {
milestone(ordinal: 100, label: 'deploy to latest.test.molgenis.org')
dir("${JENKINS_AGENT_WORKDIR}/.rancher") {
unstash 'rancher-config'
}
container('rancher') {
sh "rancher context switch test-molgenis"
sh "rancher apps upgrade --set image.tag=${TAG} latest ${CHART_VERSION}"
}
}
}
}
}
stage('Steps [ feature ]') {
when {
expression { BRANCH_NAME ==~ /feature\/.*/ }
}
environment {
TAG = "$BRANCH_NAME-$BUILD_NUMBER".replaceAll(~/[^\w.-]/, '-').toLowerCase()
}
stages {
stage('Build, test and publish [ feature ]') {
steps {
container('maven') {
sh "mvn -q -B clean deploy -Dmaven.test.redirectTestOutputToFile=true -DskipITs -jib.tag=${TAG} -Djib.repository=${LOCAL_REPOSITORY}"
sh "mvn -q -B sonar:sonar -Dsonar.branch.name=${BRANCH_NAME} -Dsonar.login=${SONAR_TOKEN} -Dsonar.ws.timeout=120"
}
}
post {
always {
junit '**/target/surefire-reports/**.xml'
}
}
}
}
}
}
}