-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
135 lines (121 loc) · 4.63 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
#!groovy
def workerNode = "devel11-java11"
void notifyOfBuildStatus(final String buildStatus) {
final String subject = "${buildStatus}: ${env.JOB_NAME} #${env.BUILD_NUMBER}"
final String details = """<p> Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p>Check console output at "<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>"""
emailext(
subject: "$subject",
body: "$details", attachLog: true, compressLog: false,
mimeType: "text/html",
recipientProviders: [[$class: "CulpritsRecipientProvider"]]
)
}
pipeline {
agent { label workerNode }
triggers {
pollSCM("H/03 * * * *")
}
options {
timestamps()
}
environment {
MARATHON_TOKEN = credentials("METASCRUM_MARATHON_TOKEN")
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("Verify") {
steps {
sh "mvn -B verify pmd:pmd"
junit "**/target/surefire-reports/TEST-*.xml,**/target/failsafe-reports/TEST-*.xml"
}
}
stage("Publish PMD Results") {
steps {
step([$class : 'hudson.plugins.pmd.PmdPublisher',
pattern : '**/target/pmd.xml',
unstableTotalAll: "0",
failedTotalAll : "0"])
}
}
stage("DIT test") {
steps {
script {
sh "rm -rf core"
}
dir("core") {
git(credentialsId: 'gitlab-meta', url: "[email protected]:pu/dit-core.git")
script {
sh """
bash -c '
source bin/activate ../
run --junit -s VERIFIED
'
"""
junit "reports/*.xml"
}
}
}
}
stage("Docker build") {
when {
expression {
currentBuild.result == null || currentBuild.result == 'SUCCESS'
}
}
steps {
script {
// Build and push indexer
def image = docker.build("docker-metascrum.artifacts.dbccloud.dk/rawrepo-solr-indexer:${DOCKER_IMAGE_VERSION}",
" --label jobname=${env.JOB_NAME}" +
" --label gitcommit=${env.GIT_COMMIT}" +
" --label buildnumber=${env.BUILD_NUMBER}" +
" --label user=isworker" +
" .")
image.push()
}
}
}
stage("Update deployments") {
agent {
docker {
label workerNode
image "docker-dbc.artifacts.dbccloud.dk/build-env:latest"
alwaysPull true
}
}
when {
expression {
(currentBuild.result == null || currentBuild.result == 'SUCCESS') && env.BRANCH_NAME == 'master'
}
}
steps {
script {
dir("deploy") {
sh """
set-new-version rawrepo-solr-indexer.yml ${env.GITLAB_PRIVATE_TOKEN} metascrum/rawrepo-solr-indexer-deployer ${DOCKER_IMAGE_VERSION} -b metascrum-staging
set-new-version rawrepo-solr-indexer.yml ${env.GITLAB_PRIVATE_TOKEN} metascrum/rawrepo-solr-indexer-deployer ${DOCKER_IMAGE_VERSION} -b basismig
set-new-version rawrepo-solr-indexer.yml ${env.GITLAB_PRIVATE_TOKEN} metascrum/rawrepo-solr-indexer-deployer ${DOCKER_IMAGE_VERSION} -b fbstest
set-new-version services/rawrepo-solr/rawrepo-solr-indexer-service.yml ${env.GITLAB_PRIVATE_TOKEN} metascrum/dit-gitops-secrets ${DOCKER_IMAGE_VERSION} -b master
"""
}
}
}
}
}
post {
unstable {
notifyOfBuildStatus("Build became unstable")
}
failure {
notifyOfBuildStatus("Build failed")
}
}
}