-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJenkinsfile
224 lines (190 loc) · 8.73 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!groovy
@Library(['github.com/cloudogu/[email protected]', 'github.com/cloudogu/[email protected]'])
import com.cloudogu.ces.cesbuildlib.*
import com.cloudogu.ces.dogubuildlib.*
String doguName = 'smeagol'
String branch = "${env.BRANCH_NAME}"
String defaultEmailRecipients = env.EMAIL_RECIPIENTS
Git git = new Git(this, "cesmarvin")
git.committerName = 'cesmarvin'
git.committerEmail = '[email protected]'
GitFlow gitflow = new GitFlow(this, git)
GitHub github = new GitHub(this, git)
Changelog changelog = new Changelog(this)
EcoSystem ecoSystem = new EcoSystem(this, "gcloud-ces-operations-internal-packer", "jenkins-gcloud-ces-operations-internal")
Trivy trivy = new Trivy(this, ecoSystem)
parallel(
"source code": {
node() { // No specific label
timestamps {
def mvnDockerName = '3.9.8-eclipse-temurin-21'
Maven mvn = new MavenInDocker(this, mvnDockerName)
stage('Checkout') {
checkout scm
git.clean("")
}
stage('Check Markdown Links') {
Markdown markdown = new Markdown(this)
markdown.check()
}
stage('Lint') {
lintDockerfile()
}
stage('Shellcheck') {
shellCheck("resources/startup.sh")
}
stage('Build') {
setupMaven(mvn)
// Tui-Editor 1.4.10 has git:// dependencies.
// Replace git:// with https:// for github dependencies because the unauthenticated protocol is no longer
// supported.
sh 'sed -i "s/git:\\/\\/github/https:\\/\\/github/g" yarn.lock'
mvn 'clean install -DskipTests -Dmaven.wagon.http.pool=false'
archive '**/target/*.*ar,**/target/*.zip'
}
stage('Unit Test') {
mvn 'test'
}
stage('SonarQube') {
def scannerHome = tool name: 'sonar-scanner', type: 'hudson.plugins.sonar.SonarRunnerInstallation'
withSonarQubeEnv {
sh "git config 'remote.origin.fetch' '+refs/heads/*:refs/remotes/origin/*'"
gitWithCredentials("fetch --all")
if (branch == "master") {
echo "This branch has been detected as the master branch."
sh "${scannerHome}/bin/sonar-scanner"
} else if (branch == "develop") {
echo "This branch has been detected as the develop branch."
sh "${scannerHome}/bin/sonar-scanner -Dsonar.branch.name=${env.BRANCH_NAME} -Dsonar.branch.target=master "
} else if (env.CHANGE_TARGET) {
echo "This branch has been detected as a pull request."
sh "${scannerHome}/bin/sonar-scanner -Dsonar.branch.name=${env.CHANGE_BRANCH}-PR${env.CHANGE_ID} -Dsonar.branch.target=${env.CHANGE_TARGET} "
} else if (branch.startsWith("feature/")) {
echo "This branch has been detected as a feature branch."
sh "${scannerHome}/bin/sonar-scanner -Dsonar.branch.name=${env.BRANCH_NAME} -Dsonar.branch.target=develop"
} else if (branch.startsWith("bugfix/")) {
echo "This branch has been detected as a bugfix branch."
sh "${scannerHome}/bin/sonar-scanner -Dsonar.branch.name=${env.BRANCH_NAME} -Dsonar.branch.target=develop"
} else {
echo "This branch has been detected as a miscellaneous branch."
sh "${scannerHome}/bin/sonar-scanner -Dsonar.branch.name=${env.BRANCH_NAME} -Dsonar.branch.target=develop"
}
}
timeout(time: 2, unit: 'MINUTES') { // Needed when there is no webhook for example
def qGate = waitForQualityGate()
if (qGate.status != 'OK') {
unstable("Pipeline unstable due to SonarQube quality gate failure")
}
}
}
// Archive Unit and integration test results, if any
junit allowEmptyResults: true, testResults: '**/target/failsafe-reports/TEST-*.xml,**/target/surefire-reports/TEST-*.xml,**/target/jest-reports/TEST-*.xml'
mailIfStatusChanged(findEmailRecipients(defaultEmailRecipients))
}
}
},
"dogu-integration": {
node("vagrant") { // No specific label
sh 'echo testing dogu integration with ces'
timestamps {
properties([
// Keep only the last 10 build to preserve space
buildDiscarder(logRotator(numToKeepStr: '10')),
// Don't run concurrent builds for a branch, because they use the same workspace directory
disableConcurrentBuilds(),
parameters([
booleanParam(defaultValue: true, description: 'Enables cypress to record video of the integration tests.', name: 'EnableVideoRecording'),
booleanParam(defaultValue: true, description: 'Enables cypress to take screenshots of failing integration tests.', name: 'EnableScreenshotRecording'),
booleanParam(defaultValue: false, description: 'Test dogu upgrade from latest release or optionally from defined version below', name: 'TestDoguUpgrade'),
string(defaultValue: '', description: 'Old Dogu version for the upgrade test (optional; e.g. 2.222.1-1)', name: 'OldDoguVersionForUpgradeTest'),
])
])
catchError {
stage('Checkout') {
checkout scm
git.clean("")
}
try {
stage('Provision') {
ecoSystem.provision("/dogu")
}
stage('Setup') {
ecoSystem.loginBackend('cesmarvin-setup')
ecoSystem.setup([additionalDependencies: ['official/scm']])
}
stage('Wait for dependencies') {
timeout(15) {
ecoSystem.waitForDogu("scm")
}
}
stage('Build') {
ecoSystem.build("/dogu")
}
stage('Trivy scan') {
trivy.scanDogu("/dogu", TrivyScanFormat.HTML, TrivyScanLevel.CRITICAL, TrivyScanStrategy.UNSTABLE)
trivy.scanDogu("/dogu", TrivyScanFormat.JSON, TrivyScanLevel.CRITICAL, TrivyScanStrategy.UNSTABLE)
trivy.scanDogu("/dogu", TrivyScanFormat.PLAIN, TrivyScanLevel.CRITICAL, TrivyScanStrategy.UNSTABLE)
}
stage('Verify') {
ecoSystem.verify("/dogu")
}
stage('Integration tests') {
ecoSystem.runCypressIntegrationTests([enableVideo : params.EnableVideoRecording,
enableScreenshots : params.EnableScreenshotRecording,
cypressImage : "cypress/included:12.17.1",])
}
if (params.TestDoguUpgrade != null && params.TestDoguUpgrade) {
stage('Upgrade dogu') {
// Remove new dogu that has been built and tested above
ecoSystem.purgeDogu(doguName)
if (params.OldDoguVersionForUpgradeTest != '' && !params.OldDoguVersionForUpgradeTest.contains('v')) {
println "Installing user defined version of dogu: " + params.OldDoguVersionForUpgradeTest
ecoSystem.installDogu("official/" + doguName + " " + params.OldDoguVersionForUpgradeTest)
} else {
println "Installing latest released version of dogu..."
ecoSystem.installDogu("official/" + doguName)
}
ecoSystem.startDogu(doguName)
ecoSystem.waitForDogu(doguName)
ecoSystem.upgradeDogu(ecoSystem)
// Wait for upgraded dogu to get healthy
ecoSystem.waitForDogu(doguName)
}
}
if (gitflow.isReleaseBranch()) {
String releaseVersion = git.getSimpleBranchName()
stage('Finish Release') {
gitflow.finishRelease(releaseVersion)
}
stage('Push Dogu to registry') {
ecoSystem.push("/dogu")
}
stage('Add Github-Release') {
github.createReleaseWithChangelog(releaseVersion, changelog)
}
}
} finally {
stage('Clean') {
ecoSystem.destroy()
}
}
}
mailIfStatusChanged(findEmailRecipients(defaultEmailRecipients))
}
}
}
)
def setupMaven(mvn) {
if ("master".equals(env.BRANCH_NAME)) {
mvn.additionalArgs = "-DperformRelease"
currentBuild.description = mvn.getVersion()
}
}
void gitWithCredentials(String command) {
withCredentials([usernamePassword(credentialsId: 'cesmarvin', usernameVariable: 'GIT_AUTH_USR', passwordVariable: 'GIT_AUTH_PSW')]) {
sh(
script: "git -c credential.helper=\"!f() { echo username='\$GIT_AUTH_USR'; echo password='\$GIT_AUTH_PSW'; }; f\" " + command,
returnStdout: true
)
}
}