-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
132 lines (123 loc) · 3.88 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
properties([
[$class: 'BuildDiscarderProperty',
strategy: [
$class: 'EnhancedOldBuildDiscarder',
daysToKeepStr: '10', numToKeepStr: '10',
discardOnlyOnSuccess: true, holdMaxBuilds: true
]
]
]);
node {
def PYTHON_MKP_REPO = "git+https://github.com/inettgmbh/python-mkp.git@0.6"
def DOCKER_BUILD_ARGS = "--build-arg USER_ID=\$(id -u) --build-arg GROUP_ID=\$(id -g)"
def t_di_1
def t_di_2
def releaseVersion
stage('Checkout') {
checkout scm
def lastTag = sh(
returnStdout: true,
script: "git tag --sort version:refname | tail -1"
).trim()
def thisCommitTag = sh(
returnStdout: true,
script: "git tag --points-at HEAD"
)
if (thisCommitTag != null) {
thisCommitTag = thisCommitTag.trim()
}
if (thisCommitTag != null && thisCommitTag != "") {
releaseVersion = thisCommitTag
} else {
releaseVersion = env.BRANCH_NAME+"-"+env.BUILD_ID
}
}
def parallel_list = []
def parallel_dependencies = [:]
parallel_dependencies.put("log4j2-scanner", {
stage("Container log4j-scanner-build") {
t_di_1 = docker.build(
"log4j-scanner-build:${env.BRANCH_NAME}-${env.BUILD_ID}",
"${DOCKER_BUILD_ARGS} log4j-scanner"
)
}
stage("Build log4j2-scanne") {
docker.image(t_di_1.id).inside {
dir('log4j-scanner') {
sh "mvn clean package"
}
}
}
stage("Archive and stash artifacts") {
dir('log4j-scanner/target') {
archiveArtifacts artifacts: '*.jar', fingerprint: true
archiveArtifacts artifacts: 'log4j_scanner', fingerprint: true
stash includes: 'log4j_scanner', name: 'log4j_scanner'
}
}
} )
parallel_dependencies.put("mkp", {
stage("Build docker container") { t_di_2 = docker.build(
"log4j-scanner-build-mkp:${env.BRANCH_NAME}-${env.BUILD_ID}",
"${DOCKER_BUILD_ARGS} --build-arg PYTHON_MKP_REPO=${PYTHON_MKP_REPO} " +
"mkp"
) }
stage("Prepare Build") { dir('mkp') {
sh 'chmod +x build/mkp-pack build/update-version'
sh 'mkdir -pv agents/plugins'
} }
} )
parallel_build = [:]
parallel_build.put("log4j2-scanner", {
stage("Cleanup container image") {
if(t_di_1 && t_di_1.id) {
sh "docker rmi ${t_di_1.id}"
t_di_1 = null
}
}
} )
parallel_build.put("mkp", {
stage('Unstash scanner') {
dir('mkp/agents/plugins') {
unstash 'log4j_scanner'
}
}
stage('package mkp') {
docker.image(t_di_2.id).inside {
dir('mkp') {
sh "build/update-version ${releaseVersion}"
sh 'build/mkp-pack'
}
}
}
stage('Archive Artifacts') {
dir('mkp') {
archiveArtifacts artifacts: '*.mkp', fingerprint: true
}
}
stage("Remove image log4j-scanner-build-mkp") {
if(t_di_2 && t_di_2.id) {
sh "docker rmi ${t_di_2.id}"
t_di_2 = null
}
}
} )
parallel_list.add(parallel_dependencies)
parallel_list.add(parallel_build)
try {
parallel(parallel_dependencies)
parallel(parallel_build)
stage("Cleanup") {
cleanWs()
}
} finally {
stage('Delete docker containers') {
if(t_di_1 && t_di_1.id) {
sh "docker rmi ${t_di_1.id}"
}
if(t_di_2 && t_di_2.id) {
sh "docker rmi ${t_di_2.id}"
}
}
}
}