-
Notifications
You must be signed in to change notification settings - Fork 228
/
Jenkinsfile
102 lines (89 loc) · 3.07 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
@Library('github.com/triologygmbh/jenkinsfile@ad12c8a9') _
pipeline {
agent none // Each stage uses its own agent
options {
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '10'))
}
stages {
stage('Build') {
agent { label 'docker' } // Require a build executor with docker
steps {
createPipelineTriggers()
mvn 'clean install -DskipTests'
archiveArtifacts '**/target/*.*ar'
}
}
stage('Tests') {
parallel {
stage('Unit Test') {
agent { label 'docker' } // Require a build executor with docker
steps {
mvn 'test'
}
post {
always {
junit allowEmptyResults: true, testResults: '**/target/surefire-reports/TEST-*.xml'
}
}
}
stage('Integration Test') {
agent { label 'docker' } // Require a build executor with docker
when { expression { return isTimeTriggeredBuild() } }
steps {
mvn 'verify -DskipUnitTests -Parq-wildfly-swarm '
}
post {
always {
junit allowEmptyResults: true, testResults: '**/target/failsafe-reports/*.xml'
}
}
}
}
}
stage('Statical Code Analysis') {
agent { label 'docker' } // Require a build executor with docker
steps {
withSonarQubeEnv('sonarcloud.io-cloudogu') {
mvn "$SONAR_MAVEN_GOAL -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.login=$SONAR_AUTH_TOKEN " +
// Here, we could define e.g. sonar.organization, needed for sonarcloud.io
"$SONAR_EXTRA_PROPS " +
// Additionally needed when using the branch plugin (e.g. on sonarcloud.io)
"-Dsonar.branch.name=$BRANCH_NAME -Dsonar.branch.target=master"
}
}
}
stage('Quality Gate') {
steps {
waitForQualityGateAndSetResult()
}
}
}
post {
always {
node('') {
mailIfStatusChanged env.EMAIL_RECIPIENTS
}
}
}
}
void createPipelineTriggers() {
script {
def triggers = []
if (env.BRANCH_NAME == 'master') {
// Run a nightly only for master
triggers = [cron('H H(0-3) * * 1-5')]
}
properties([
pipelineTriggers(triggers)
])
}
}
void waitForQualityGateAndSetResult() {
timeout(time: 2, unit: 'MINUTES') {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
unstable("Pipeline unstable due to quality gate failure: ${qg.status}")
}
}
}