-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
128 lines (112 loc) · 5.21 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
#!groovy
def workerNode = 'devel11'
def teamEmail = '[email protected]'
def teamSlack = 'de-notifications'
def DOCKER_PUSH_TAG = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}"
pipeline {
agent { label workerNode }
environment {
GITLAB_PRIVATE_TOKEN = credentials("metascrum-gitlab-api-token")
}
triggers {
pollSCM("H/3 * * * *")
// This project uses the docker.dbc.dk/payara5-micro container
upstream('/Docker-payara6-bump-trigger')
}
options {
buildDiscarder(logRotator(artifactDaysToKeepStr: "", artifactNumToKeepStr: "", daysToKeepStr: "30", numToKeepStr: "30"))
timestamps()
}
stages {
stage("Ready the Workspace") {
steps {
deleteDir()
checkout scm
script {
if (env.BRANCH_NAME == 'master') {
DOCKER_PUSH_TAG = "${env.BUILD_NUMBER}"
}
}
}
}
stage("Build & Push") {
steps {
script {
def status = sh returnStatus: true, script: """
rm -rf \$WORKSPACE/.repo
mvn -B -Dmaven.repo.local=\$WORKSPACE/.repo dependency:resolve dependency:resolve-plugins >/dev/null
mvn -B -Dmaven.repo.local=\$WORKSPACE/.repo clean
"""
// We want code-coverage and pmd/spotbugs even if unittests fails
status += sh returnStatus: true, script: """
mvn -B -Dmaven.repo.local=\$WORKSPACE/.repo verify pmd:pmd pmd:cpd spotbugs:spotbugs javadoc:aggregate
"""
junit testResults: '**/target/*-reports/*.xml'
def java = scanForIssues tool: [$class: 'Java']
def javadoc = scanForIssues tool: [$class: 'JavaDoc']
publishIssues issues: [java, javadoc], unstableTotalAll: 1
def pmd = scanForIssues tool: [$class: 'Pmd']
publishIssues issues: [pmd], unstableTotalAll: 1
def spotbugs = scanForIssues tool: [$class: 'SpotBugs']
publishIssues issues: [spotbugs], unstableTotalAll: 1
if (status != 0) {
error("Build failure")
} else {
docker.image("docker-de.artifacts.dbccloud.dk/ess-payara-service-1.0:${DOCKER_PUSH_TAG}").push()
if ("${env.BRANCH_NAME}" == 'master') {
docker.image("docker-de.artifacts.dbccloud.dk/ess-payara-service-1.0:${DOCKER_PUSH_TAG}").push('latest')
}
}
}
}
}
}
post {
fixed {
script {
if ("${env.BRANCH_NAME}" == 'master') {
emailext(
recipientProviders: [developers(), culprits()],
to: teamEmail,
subject: "[Jenkins] ${env.JOB_NAME} #${env.BUILD_NUMBER} back to normal",
mimeType: 'text/html; charset=UTF-8',
body: "<p>The master is back to normal.</p><p><a href=\"${env.BUILD_URL}\">Build information</a>.</p>",
attachLog: false)
slackSend(channel: teamSlack,
color: 'good',
message: "${env.JOB_NAME} #${env.BUILD_NUMBER} back to normal: ${env.BUILD_URL}",
tokenCredentialId: 'slack-global-integration-token')
}
}
}
failure {
script {
if ("${env.BRANCH_NAME}" == 'master') {
emailext(
recipientProviders: [developers(), culprits()],
to: teamEmail,
subject: "[Jenkins] ${env.JOB_NAME} #${env.BUILD_NUMBER} failed",
mimeType: 'text/html; charset=UTF-8',
body: "<p>The master build failed. Log attached.</p><p><a href=\"${env.BUILD_URL}\">Build information</a>.</p>",
attachLog: true
)
slackSend(channel: teamSlack,
color: 'warning',
message: "${env.JOB_NAME} #${env.BUILD_NUMBER} failed and needs attention: ${env.BUILD_URL}",
tokenCredentialId: 'slack-global-integration-token')
} else {
emailext(
recipientProviders: [developers()],
subject: "[Jenkins] ${env.BUILD_TAG} failed and needs your attention",
mimeType: 'text/html; charset=UTF-8',
body: "<p>${env.BUILD_TAG} failed and needs your attention. </p><p><a href=\"${env.BUILD_URL}\">Build information</a>.</p>",
attachLog: false
)
}
}
}
success {
step([$class: 'JavadocArchiver', javadocDir: 'target/reports/apidocs', keepAll: false])
}
}
}