-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkinsfile.groovy
105 lines (98 loc) · 3.03 KB
/
jenkinsfile.groovy
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
pipeline {
/*
* Run everything on an existing agent configured with a label 'docker'.
* This agent will need docker, git and a jdk installed at a minimum.
*/
agent {
node {
label 'docker'
}
}
// using the Timestamper plugin we can add timestamps to the console log
options {
timestamps()
}
environment {
//Use Pipeline Utility Steps plugin to read information from pom.xml into env variables
IMAGE = readMavenPom().getArtifactId()
VERSION = readMavenPom().getVersion()
}
stages {
stage('Build') {
agent {
docker {
/*
* Reuse the workspace on the agent defined at top-level of Pipeline but run inside a container.
* In this case we are running a container with maven so we don't have to install specific versions
* of maven directly on the agent
*/
reuseNode true
image 'maven:3.5.0-jdk-8'
}
}
steps {
// using the Pipeline Maven plugin we can set maven configuration settings, publish test results, and annotate the Jenkins console
withMaven(options: [findbugsPublisher(), junitPublisher(ignoreAttachments: false)]) {
sh 'mvn clean findbugs:findbugs package'
}
}
post {
success {
// we only worry about archiving the jar file if the build steps are successful
archiveArtifacts(artifacts: '**/target/*.jar', allowEmptyArchive: true)
}
}
}
stage('Quality Analysis') {
parallel {
// run Sonar Scan and Integration tests in parallel. This syntax requires Declarative Pipeline 1.2 or higher
stage ('Integration Test') {
agent any //run this stage on any available agent
steps {
echo 'Run integration tests here...'
}
}
stage('Sonar Scan') {
agent {
docker {
// we can use the same image and workspace as we did previously
reuseNode true
image 'maven:3.5.0-jdk-8'
}
}
environment {
//use 'sonar' credentials scoped only to this stage
SONAR = credentials('sonar')
}
steps {
sh 'mvn sonar:sonar -Dsonar.login=$SONAR_PSW'
}
}
}
}
stage('Build and Publish Image') {
when {
branch 'master' //only run these steps on the master branch
}
steps {
/*
* Multiline strings can be used for larger scripts. It is also possible to put scripts in your shared library
* and load them with 'libaryResource'
*/
sh """
docker build -t ${IMAGE} .
docker tag ${IMAGE} ${IMAGE}:${VERSION}
docker push ${IMAGE}:${VERSION}
"""
}
}
}
post {
failure {
// notify users when the Pipeline fails
mail to: '[email protected]',
subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
body: "Something is wrong with ${env.BUILD_URL}"
}
}
}