-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
141 lines (124 loc) · 5.06 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
#!groovy
String workerNode = "devel11"
String slackChannel = "meta-notifications"
pipeline {
agent { label workerNode }
tools {
maven "Maven 3"
}
triggers {
pollSCM("H/03 * * * *")
upstream(upstreamProjects: "Docker-payara6-bump-trigger",
threshold: hudson.model.Result.SUCCESS)
}
options {
timestamps()
}
environment {
DOCKER_IMAGE_NAME = "docker-metascrum.artifacts.dbccloud.dk/rawrepo-introspect-backend"
DOCKER_IMAGE_VERSION = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}"
GITLAB_PRIVATE_TOKEN = credentials("metascrum-gitlab-api-token")
}
stages {
stage("Clean Workspace") {
steps {
deleteDir()
checkout scm
}
}
stage('Build') {
steps {
sh "mvn verify pmd:pmd pmd:cpd spotbugs:spotbugs"
junit testResults: '**/target/surefire-reports/TEST-*.xml,**/target/failsafe-reports/TEST-*.xml'
script {
def java = scanForIssues tool: [$class: 'Java']
def javadoc = scanForIssues tool: [$class: 'JavaDoc']
publishIssues issues: [java, javadoc], unstableTotalAll: 0
def pmd = scanForIssues tool: [$class: 'Pmd']
publishIssues issues: [pmd], unstableTotalAll: 1
// spotbugs still has some outstanding issues with regard
// to analyzing Java 11 bytecode.
// def spotbugs = scanForIssues tool: [$class: 'SpotBugs']
// publishIssues issues:[spotbugs], unstableTotalAll:1
}
}
}
stage("Docker build") {
when {
expression {
currentBuild.result == null || currentBuild.result == 'SUCCESS'
}
}
steps {
script {
def image = docker.build("${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}", '--pull --no-cache .')
image.push()
}
}
}
stage("Bump deploy version") {
agent {
docker {
label workerNode
image "docker-dbc.artifacts.dbccloud.dk/build-env:latest"
alwaysPull true
}
}
when {
expression {
currentBuild.result == null || currentBuild.result == 'SUCCESS'
}
}
steps {
script {
if (env.BRANCH_NAME == 'master') {
sh """
set-new-version rawrepo-introspect-backend.yml ${env.GITLAB_PRIVATE_TOKEN} metascrum/rawrepo-introspect-deploy ${DOCKER_IMAGE_VERSION} -b metascrum-staging
set-new-version rawrepo-introspect-backend.yml ${env.GITLAB_PRIVATE_TOKEN} metascrum/rawrepo-introspect-deploy ${DOCKER_IMAGE_VERSION} -b fbstest
set-new-version rawrepo-introspect-backend.yml ${env.GITLAB_PRIVATE_TOKEN} metascrum/rawrepo-introspect-deploy ${DOCKER_IMAGE_VERSION} -b fbstest-dm3
set-new-version rawrepo-introspect-backend.yml ${env.GITLAB_PRIVATE_TOKEN} metascrum/rawrepo-introspect-deploy ${DOCKER_IMAGE_VERSION} -b basismig
set-new-version services/rawrepo/rawrepo-introspect-backend.yml ${env.GITLAB_PRIVATE_TOKEN} metascrum/dit-gitops-secrets ${DOCKER_IMAGE_VERSION} -b master
"""
}
}
}
}
}
post {
always {
sh """
docker rmi "${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}"
"""
}
failure {
script {
if (BRANCH_NAME == "master") {
slackSend(channel: "${slackChannel}",
color: 'warning',
message: "${JOB_NAME} #${BUILD_NUMBER} failed and needs attention: ${BUILD_URL}",
tokenCredentialId: 'slack-global-integration-token')
}
}
}
success {
script {
if (BRANCH_NAME == 'master') {
slackSend(channel: "${slackChannel}",
color: 'good',
message: "${JOB_NAME} #${BUILD_NUMBER} completed, and pushed ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION} to artifactory.",
tokenCredentialId: 'slack-global-integration-token')
}
}
}
fixed {
script {
if (BRANCH_NAME == 'master') {
slackSend(channel: "${slackChannel}",
color: 'good',
message: "${JOB_NAME} #${BUILD_NUMBER} back to normal: ${BUILD_URL}",
tokenCredentialId: 'slack-global-integration-token')
}
}
}
}
}