forked from camunda-community-hub/zeebe-http-worker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
170 lines (156 loc) · 5.25 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
167
168
169
170
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-11
command: ["cat"]
tty: true
resources:
limits:
cpu: 1
memory: 2Gi
requests:
cpu: 1
memory: 2Gi
- name: docker
image: docker:18.09.4-dind
args: ["--storage-driver=overlay2"]
securityContext:
privileged: true
tty: true
resources:
limits:
cpu: 1
memory: 1Gi
requests:
cpu: 500m
memory: 512Mi
'''
}
}
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
timestamps()
timeout(time: 15, unit: 'MINUTES')
}
environment {
NEXUS = credentials("camunda-nexus")
DOCKER_HUB = credentials("camunda-dockerhub")
}
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 'apt-get update'
sh 'apt-get install --no-install-recommends -qq -y libatomic1'
sh 'mvn clean install -B -s $MAVEN_SETTINGS_XML -DskipTests'
}
}
container('docker') {
sh 'docker login --username ${DOCKER_HUB_USR} --password ${DOCKER_HUB_PSW}'
}
}
}
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'
}
}
container('docker') {
sh 'docker build -t camunda/zeebe-http-worker:SNAPSHOT .'
}
}
post {
always {
junit testResults: "**/*/TEST-*.xml", keepLongStdio: true
}
}
}
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'
}
}
container('docker') {
sh 'docker push camunda/zeebe-http-worker:SNAPSHOT'
}
}
}
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 "[email protected]"'
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'
}
}
}
container('docker') {
sh 'docker build -t camunda/zeebe-http-worker:SNAPSHOT .'
sh 'docker tag camunda/zeebe-http-worker:SNAPSHOT camunda/zeebe-http-worker:${RELEASE_VERSION}'
sh 'docker push camunda/zeebe-http-worker:${RELEASE_VERSION}'
sh 'docker tag camunda/zeebe-http-worker:SNAPSHOT camunda/zeebe-http-worker:latest'
sh 'docker push camunda/zeebe-http-worker:latest'
}
}
}
}
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).*/
}