forked from jenkins-docs/simple-java-maven-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
88 lines (84 loc) · 2.55 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
if (env.BRANCH_NAME == 'master')
myBranch = ''
else
myBranch = env.BRANCH_NAME
node {
echo "Jenkins variables"
echo env.BRANCH_NAME
echo myBranch
echo env.CHANGE_ID
echo env.CHANGE_BRANCH
echo env.CHANGE_TARGET
}
if(env.CHANGE_ID != null) // PR analysis
mvnCmdLine = "mvn -X -B -DskipTests \
-Dsonar.pullrequest.key=${env.CHANGE_ID} \
-Dsonar.pullrequest.branch=${myBranch} \
-Dsonar.pullrequest.base=${env.CHANGE_TARGET} \
clean package sonar:sonar"
else // regular branch analysis
mvnCmdLine = "mvn -X -B -DskipTests \
-Dsonar.branch.name=${myBranch} \
clean package sonar:sonar"
node {
echo "My command line:"
echo mvnCmdLine
}
pipeline {
agent {
docker {
// image 'masstroy/alpine-docker-java-maven'
image 'maven:3-alpine'
args '-v maven-cache:/root/.m2 \
-v sonar-cache:/root/.sonar/cache'
}
}
options {
skipStagesAfterUnstable()
}
stages {
stage('SCM') {
steps {
// git 'https://github.com/sylvain-combe-sonarsource/simple-java-maven-app.git'
// sh "git fetch --no-tags ${GIT_URL} +refs/heads/master:refs/remotes/origin/master"
sh "echo ${GIT_URL}"
}
}
stage('Build') {
steps {
withSonarQubeEnv(installationName: 'SQ82') {
// script {
// fetch master from origin so sonar scanner comparison works
// sh "git fetch --no-tags ${GIT_URL} +refs/heads/master:refs/remotes/origin/master"
sh "${mvnCmdLine}"
// sh 'mvn clean package sonar:sonar'
// }
}
}
}
stage('Test') {
steps {
sh 'mvn test'
}
post {
always {
junit 'target/surefire-reports/*.xml'
}
}
}
stage('Deliver') {
steps {
sh './jenkins/scripts/deliver.sh'
}
}
stage("Quality Gate") {
steps {
timeout(time: 1, unit: 'HOURS') {
// Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails
// true = set pipeline to UNSTABLE, false = don't
waitForQualityGate abortPipeline: true
}
}
}
}
}