forked from senbox-org/snap-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
184 lines (182 loc) · 8.59 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
178
179
180
181
182
183
184
#!/usr/bin/env groovy
/**
* Copyright (C) 2019 CS-SI
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
pipeline {
environment {
toolName = sh(returnStdout: true, script: "echo ${env.JOB_NAME} | cut -d '/' -f 1").trim()
branchVersion = sh(returnStdout: true, script: "echo ${env.GIT_BRANCH} | cut -d '/' -f 2").trim()
toolVersion = ''
deployDirName = ''
snapMajorVersion = ''
sonarOption = ""
}
agent { label 'snap-test' }
parameters {
booleanParam(name: 'launchTests', defaultValue: true, description: 'When true all stages are launched, When false only stages "Package", "Deploy" and "Save installer data" are launched.')
}
stages {
stage('Package') {
agent {
docker {
label 'snap-test'
image 'snap-build-server.tilaa.cloud/maven:3.6.0-jdk-8'
args '-e MAVEN_CONFIG=/var/maven/.m2 -v /data/ssd/testData/:/data/ssd/testData/ -v /opt/maven/.m2/settings.xml:/var/maven/.m2/settings.xml'
}
}
steps {
script {
// Get snap version from pom file
toolVersion = sh(returnStdout: true, script: "cat pom.xml | grep '<version>' | head -1 | cut -d '>' -f 2 | cut -d '-' -f 1 | cut -d '<' -f 1").trim()
snapMajorVersion = sh(returnStdout: true, script: "echo ${toolVersion} | cut -d '.' -f 1").trim()
deployDirName = "${toolName}/${branchVersion}-${toolVersion}-${env.GIT_COMMIT}"
sonarOption = ""
if ("${branchVersion}" == "master") {
// Only use sonar on master branch
sonarOption = "sonar:sonar"
}
}
echo "Build Job ${env.JOB_NAME} from ${env.GIT_BRANCH} with commit ${env.GIT_COMMIT}"
sh "mvn -Duser.home=/var/maven -Dsnap.userdir=/home/snap clean package install ${sonarOption} -U -DskipTests=false"
}
post {
always {
junit "**/target/surefire-reports/*.xml"
jacoco(execPattern: '**/*.exec')
}
}
}
stage('Deploy') {
agent {
docker {
label 'snap-test'
image 'snap-build-server.tilaa.cloud/maven:3.6.0-jdk-8'
args '-e MAVEN_CONFIG=/var/maven/.m2 -v /opt/maven/.m2/settings.xml:/var/maven/.m2/settings.xml -v docker_local-update-center:/local-update-center'
}
}
when {
expression {
return "${env.GIT_BRANCH}" == 'master' || "${env.GIT_BRANCH}" =~ /\d+\.x/ || "${env.GIT_BRANCH}" =~ /\d+\.\d+\.\d+(-rc\d+)?$/;
}
}
steps {
echo "Deploy ${env.JOB_NAME} from ${env.GIT_BRANCH} with commit ${env.GIT_COMMIT}"
sh "mvn -Duser.home=/var/maven -Dsnap.userdir=/home/snap deploy -U -DskipTests=true"
sh "/opt/scripts/saveToLocalUpdateCenter.sh . ${deployDirName} ${branchVersion} ${toolName}"
}
}
stage('Save installer data') {
agent {
docker {
label 'snap-test'
image 'snap-build-server.tilaa.cloud/scripts:1.0'
args '-v docker_snap-installer:/snap-installer'
}
}
when {
expression {
// We save snap installer data on master branch and branch x.x.x (Ex: 8.0.0) or branch x.x.x-rcx (ex: 8.0.0-rc1) when we want to create a release
return ("${env.GIT_BRANCH}" == 'master' || "${env.GIT_BRANCH}" =~ /\d+\.\d+\.\d+(-rc\d+)?$/);
}
}
steps {
echo "Save data for SNAP Installer ${env.JOB_NAME} from ${env.GIT_BRANCH} with commit ${env.GIT_COMMIT}"
sh "/opt/scripts/saveInstallData.sh ${toolName} ${env.GIT_BRANCH}"
}
}
stage('Create SNAP Installer') {
agent { label 'snap-test' }
when {
expression {
return ("${env.GIT_BRANCH}" == 'master' || "${env.GIT_BRANCH}" =~ /\d+\.\d+\.\d+(-rc\d+)?$/) && "${params.launchTests}" == "true";
}
}
steps {
echo "Launch snap-installer"
build job: "snap-installer/${env.GIT_BRANCH}"
}
}
stage('Create docker image') {
agent { label 'snap-test' }
when {
expression {
return "${params.launchTests}" == "true";
}
}
steps {
echo "Launch snap-installer"
build job: "create-snap-docker-image", parameters: [
[$class: 'StringParameterValue', name: 'toolName', value: "${toolName}"],
[$class: 'StringParameterValue', name: 'snapMajorVersion', value: "${snapMajorVersion}"],
[$class: 'StringParameterValue', name: 'deployDirName', value: "${deployDirName}"],
[$class: 'StringParameterValue', name: 'branchVersion', value: "${branchVersion}"],
[$class: 'BooleanParameterValue', name: 'maintenanceBranch', value: "false"]
],
quietPeriod: 0,
propagate: true,
wait: true
}
}
stage ('Starting Tests') {
parallel {
stage ('Starting GPT Tests') {
agent { label 'snap-test' }
when {
expression {
return ("${env.GIT_BRANCH}" == 'master' || "${env.GIT_BRANCH}" =~ /\d+\.x/ || "${env.GIT_BRANCH}" =~ /\d+\.\d+\.\d+(-rc\d+)?$/) && "${params.launchTests}" == "true";
}
}
steps {
echo "Launch snap-gpt-tests using docker image snap:${branchVersion} and scope REGULAR"
build job: "snap-gpt-tests/${branchVersion}", parameters: [
[$class: 'StringParameterValue', name: 'dockerTagName', value: "snap:${branchVersion}"],
[$class: 'StringParameterValue', name: 'testScope', value: "REGULAR"]
]
}
}
stage ('Starting GUI Tests') {
agent { label 'snap-test' }
when {
expression {
return ("${env.GIT_BRANCH}" == 'master' || "${env.GIT_BRANCH}" =~ /\d+\.x/ || "${env.GIT_BRANCH}" =~ /\d+\.\d+\.\d+(-rc\d+)?$/) && "${params.launchTests}" == "true";
}
}
steps {
echo "Launch snap-gui-tests using docker image snap:${branchVersion}"
build job: "snap-gui-tests/${branchVersion}", parameters: [
[$class: 'StringParameterValue', name: 'dockerTagName', value: "snap:${branchVersion}"],
[$class: 'StringParameterValue', name: 'testFileList', value: "qftests.lst"]
]
}
}
}
}
}
/* disable email send on failure
post {
failure {
step (
emailext(
subject: "[SNAP] JENKINS-NOTIFICATION: ${currentBuild.result ?: 'SUCCESS'} : Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: """Build status : ${currentBuild.result ?: 'SUCCESS'}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':
Check console output at ${env.BUILD_URL}
${env.JOB_NAME} [${env.BUILD_NUMBER}]""",
attachLog: true,
compressLog: true,
recipientProviders: [[$class: 'CulpritsRecipientProvider'], [$class:'DevelopersRecipientProvider']]
)
)
}
}*/
}