-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
101 lines (100 loc) · 3.65 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
pipeline {
agent none
stages {
stage('Test') {
when {
anyOf {
branch 'development'; branch pattern: 'PR-\\d+', comparator: 'REGEXP'
}
}
agent {
docker {
image 'maven:3-adoptopenjdk-8'
args '-v $HOME/.m2:/root/.m2 --network docker-ci_default'
}
}
steps {
sh 'mvn clean test sonar:sonar -Dsonar.host.url=http://sonarqube:9000/sonarqube -Dsonar.login=$SONAR_TOKEN'
}
}
stage('Build'){
when{
anyOf {
branch 'main'; branch pattern: 'iteration\\d+', comparator: 'REGEXP'
}
}
agent {
docker {
image 'maven:3-adoptopenjdk-8'
args '-v $HOME/.m2:/root/.m2 --network docker-ci_default'
}
}
steps {
sh 'mvn clean package'
}
}
stage('Docker') {
when{
branch 'main'
}
agent { label 'master' }
environment {
VERSION=readMavenPom().getVersion()
}
steps {
script{
def img
if (env.BRANCH_NAME == 'main') {
img = docker.build('de4a/demo-ui','--build-arg VERSION=$VERSION .')
docker.withRegistry('','docker-hub-token') {
img.push('latest')
img.push('$VERSION')
}
}
}
}
}
stage('Docker iteration') {
when{
branch pattern: 'iteration\\d+', comparator: 'REGEXP'
}
agent { label 'master' }
environment {
VERSION=readMavenPom().getVersion()
}
steps {
script{
def img
img = docker.build('de4a/demo-ui','--build-arg VERSION=$VERSION .')
docker.withRegistry('','docker-hub-token') {
img.push("${env.BRANCH_NAME}")
img.push('$VERSION')
}
}
}
}
}
post {
failure {
node('master') {
script {
env.ORG=env.JOB_NAME.split('/')[0]
env.REPO=env.JOB_NAME.split('/')[1]
env.BR=env.JOB_NAME.split('/')[2]
env.ERRORLOG = sh returnStdout: true, script: "cat ${env.JENKINS_HOME}/jobs/${env.ORG}/jobs/${env.REPO}/branches/${env.BR}/builds/${BUILD_NUMBER}/log | grep -B 1 -A 5 '\\[ERROR\\]'"
slackSend color: "danger", message: ":darth_maul: Build fail! :darth_maul:\nJob name: ${env.JOB_NAME}, Build number: ${env.BUILD_NUMBER}\nGit Author: ${env.CHANGE_AUTHOR}, Branch: ${env.GIT_BRANCH}, ${env.GIT_URL}\nMaven [ERROR] log below:\n ${env.ERRORLOG}"
}
}
}
success {
node('master') {
script {
if(currentBuild.getPreviousBuild() &&
currentBuild.getPreviousBuild().getResult().toString() != 'SUCCESS') {
slackSend color: "good", message: ":baby-yoda: This is the way! :baby-yoda: \nJob name: ${env.JOB_NAME}, Build number: ${env.BUILD_NUMBER}\nGit Author: ${env.CHANGE_AUTHOR}, Branch: ${env.GIT_BRANCH}, ${env.GIT_URL}\n"
}
}
}
}
}
}