-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
166 lines (152 loc) · 4.85 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
pipeline {
agent {
kubernetes {
cloud 'zeebe-ci'
label "zeebe-ci-build_${env.JOB_BASE_NAME}-${env.BUILD_ID}"
defaultContainer 'jnlp'
yaml '''\
apiVersion: v1
kind: Pod
metadata:
labels:
agent: zeebe-ci-build
spec:
nodeSelector:
cloud.google.com/gke-nodepool: slaves
tolerations:
- key: "slaves"
operator: "Exists"
effect: "NoSchedule"
containers:
- name: maven
image: maven:3.6.0-jdk-8
command: ["cat"]
tty: true
env:
- name: JAVA_TOOL_OPTIONS
value: |
-XX:+UnlockExperimentalVMOptions
-XX:+UseCGroupMemoryLimitForHeap
- name: DOCKER_HOST
value: tcp://localhost:2375
resources:
limits:
cpu: 1
memory: 2Gi
requests:
cpu: 1
memory: 2Gi
- name: dind
image: docker:18.09-dind
securityContext:
privileged: true
volumeMounts:
- name: dind-storage
mountPath: /var/lib/docker
volumes:
- name: dind-storage
emptyDir: {}
'''
}
}
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
timestamps()
timeout(time: 15, unit: 'MINUTES')
}
environment {
NEXUS = credentials("camunda-nexus")
SONARCLOUD_TOKEN = credentials('zeebe-sonarcloud-token')
}
parameters {
booleanParam(name: 'RELEASE', defaultValue: false, description: 'Build a release from current commit?')
string(name: 'RELEASE_VERSION', defaultValue: '0.X.0', description: 'Which version to release?')
string(name: 'DEVELOPMENT_VERSION', defaultValue: '0.Y.0-SNAPSHOT', description: 'Next development version?')
}
stages {
stage('Prepare') {
steps {
container('maven') {
configFileProvider([configFile(fileId: 'maven-nexus-settings-zeebe', variable: 'MAVEN_SETTINGS_XML')]) {
sh 'mvn clean install -B -s $MAVEN_SETTINGS_XML -DskipTests'
}
}
}
}
stage('Build') {
when { not { expression { params.RELEASE } } }
steps {
container('maven') {
configFileProvider([configFile(fileId: 'maven-nexus-settings-zeebe', variable: 'MAVEN_SETTINGS_XML')]) {
sh 'mvn install -B -s $MAVEN_SETTINGS_XML'
}
}
}
post {
always {
junit testResults: "**/*/TEST-*.xml", keepLongStdio: true
}
}
}
stage('Analyse') {
when { not { expression { params.RELEASE } } }
steps {
container('maven') {
configFileProvider([configFile(fileId: 'maven-nexus-settings-zeebe', variable: 'MAVEN_SETTINGS_XML')]) {
sh '.ci/scripts/analyse.sh'
}
}
}
}
stage('Upload') {
when { not { expression { params.RELEASE } } }
steps {
container('maven') {
configFileProvider([configFile(fileId: 'maven-nexus-settings-zeebe', variable: 'MAVEN_SETTINGS_XML')]) {
sh 'mvn -B -s $MAVEN_SETTINGS_XML generate-sources source:jar javadoc:jar deploy -DskipTests'
}
}
}
}
stage('Release') {
when { expression { params.RELEASE } }
environment {
MAVEN_CENTRAL = credentials('maven_central_deployment_credentials')
GPG_PASS = credentials('password_maven_central_gpg_signing_key')
GPG_PUB_KEY = credentials('maven_central_gpg_signing_key_pub')
GPG_SEC_KEY = credentials('maven_central_gpg_signing_key_sec')
GITHUB_TOKEN = credentials('camunda-jenkins-github')
RELEASE_VERSION = "${params.RELEASE_VERSION}"
DEVELOPMENT_VERSION = "${params.DEVELOPMENT_VERSION}"
}
steps {
container('maven') {
configFileProvider([configFile(fileId: 'maven-nexus-settings-zeebe', variable: 'MAVEN_SETTINGS_XML')]) {
sshagent(['camunda-jenkins-github-ssh']) {
sh 'gpg -q --import ${GPG_PUB_KEY} '
sh 'gpg -q --allow-secret-key-import --import --no-tty --batch --yes ${GPG_SEC_KEY}'
sh 'git config --global user.email "ci@camunda.com"'
sh 'git config --global user.name "camunda-jenkins"'
sh 'mkdir ~/.ssh/ && ssh-keyscan github.com >> ~/.ssh/known_hosts'
sh 'mvn -B -s $MAVEN_SETTINGS_XML -DskipTests source:jar javadoc:jar release:prepare release:perform -Prelease'
sh '.ci/scripts/github-release.sh'
}
}
}
}
}
}
post {
always {
// Retrigger the build if the node disconnected
script {
if (nodeDisconnected()) {
build job: currentBuild.projectName, propagate: false, quietPeriod: 60, wait: false
}
}
}
}
}
boolean nodeDisconnected() {
return currentBuild.rawBuild.getLog(500).join('') ==~ /.*(ChannelClosedException|KubernetesClientException|ClosedChannelException).*/
}