-
Notifications
You must be signed in to change notification settings - Fork 5
/
Jenkinsfile
110 lines (105 loc) · 3.9 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
pipeline {
agent none
stages {
stage('Test') {
when {
anyOf {
branch 'develop*';
branch 'iteration2-dev';
branch pattern: 'PR-\\d+', comparator: 'REGEXP'
}
}
agent {
docker {
image 'maven:3-adoptopenjdk-11'
args '-v $HOME/.m2:/root/.m2 --network docker-ci_default'
}
}
steps {
sh 'mvn clean test sonar:sonar -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_TOKEN'
}
}
stage('Build'){
when {
anyOf{
branch 'master';
branch pattern: 'iteration\\d+', comparator: 'REGEXP'
}
}
agent {
docker {
image 'maven:3-adoptopenjdk-11'
args '-v $HOME/.m2:/root/.m2 --network docker-ci_default'
}
}
steps {
sh 'mvn clean package -U'
}
// TODO: add pushing to a future de4a maven repo?
// TODO: add building a release on a tag and push to GitHub?
}
stage('Docker'){
when {
branch 'master'
}
agent { label 'master' }
steps {
script{
def img
if (env.BRANCH_NAME == 'master') {
dir('de4a-connector') {
env.VERSION = readMavenPom().getVersion()
img = docker.build('de4a/connector','.')
docker.withRegistry('','docker-hub-token') {
img.push('latest')
img.push("${env.VERSION}")
}
}
}
}
sh 'docker system prune -f'
sh 'docker network create docker-ci_default'
}
}
stage('Docker iteration'){
when {
branch pattern: 'iteration\\d+', comparator: 'REGEXP'
}
agent { label 'master' }
steps {
script{
def img
dir('de4a-connector') {
env.VERSION = readMavenPom().getVersion()
img = docker.build('de4a/connector','.')
docker.withRegistry('','docker-hub-token') {
img.push("${env.BRANCH_NAME}")
img.push("${env.VERSION}")
}
}
}
sh 'docker system prune -f'
}
}
}
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.BRANCH_NAME}, ${env.GIT_URL}\nMaven [ERROR] log below:\n ${env.ERRORLOG}"
}
}
}
fixed {
node('master') {
script {
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.BRANCH_NAME}, ${env.GIT_URL}\n"
}
}
}
}
}