forked from gitter-badger/daikon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
223 lines (210 loc) · 7.48 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
def gitCredentials = usernamePassword(
credentialsId: 'github-credentials',
passwordVariable: 'GIT_PASSWORD',
usernameVariable: 'GIT_LOGIN')
def jiraCredentials = usernamePassword(
credentialsId: 'jira-credentials',
passwordVariable: 'JIRA_PASSWORD',
usernameVariable: 'JIRA_LOGIN')
final def dockerRegistryCredentials = usernamePassword(
credentialsId: 'artifactory-datapwn-credentials',
passwordVariable: 'DOCKER_REGISTRY_PASSWORD',
usernameVariable: 'DOCKER_REGISTRY_USERNAME')
def currentBranch = env.BRANCH_NAME
if (BRANCH_NAME.startsWith("PR-")) {
currentBranch = env.CHANGE_BRANCH
}
pipeline {
parameters {
booleanParam(
name: "release",
description: "Build a release from current commit",
defaultValue: false)
string(
name: "release_version",
description: "Release version",
defaultValue: "0.0.0")
string(
name: "next_version",
description: "Next version",
defaultValue: "0.0.0-SNAPSHOT")
}
agent {
kubernetes {
label "all_daikon" + UUID.randomUUID().toString()
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: maven
image: artifactory.datapwn.com/tlnd-docker-prod/talend/common/tsbi/jdk17-builder-base:4.0.7-20231211094745
command:
- cat
tty: true
volumeMounts:
- name: docker
mountPath: /var/run/docker.sock
- name: m2
mountPath: /root/.m2/repository
env:
- name: DOCKER_HOST
value: tcp://localhost:2375
- name: docker-daemon
image: artifactory.datapwn.com/docker-io-remote/docker:24.0.7-dind
env:
- name: DOCKER_TLS_CERTDIR
value: ""
securityContext:
privileged: true
imagePullSecrets:
- talend-registry
volumes:
- name: docker
hostPath:
path: /var/run/docker.sock
- name: m2
persistentVolumeClaim:
claimName: efs-jenkins-common-m2
"""
}
}
environment {
MAVEN_OPTS = '-Dmaven.artifact.threads=128 -Dorg.slf4j.simpleLogger.showThreadName=true -Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss'
TESTCONTAINERS_RYUK_DISABLED = true // See https://github.com/testcontainers/testcontainers-java/issues/3609
TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX = 'artifactory.datapwn.com/docker-io-remote/library/' // Avoid rate limits on Docker hub
}
options {
buildDiscarder(logRotator(artifactNumToKeepStr: '5', numToKeepStr: env.BRANCH_NAME == 'master' ? '10' : '2'))
timeout(time: 60, unit: 'MINUTES')
skipStagesAfterUnstable()
}
stages {
stage('Check git connectivity') {
when {
expression { params.release }
}
steps {
container('maven') {
withCredentials([gitCredentials]) {
sh """
./jenkins/configure_git_credentials.sh '${GIT_LOGIN}' '${GIT_PASSWORD}'
git tag ci-kuke-test && git push --tags
git push --delete origin ci-kuke-test && git tag --delete ci-kuke-test
"""
}
}
}
}
stage('Prepare build') {
steps {
container('maven') {
script {
echo 'Login to Docker registry'
withCredentials([dockerRegistryCredentials]) {
sh """\
docker login artifactory.datapwn.com --username "${DOCKER_REGISTRY_USERNAME}" --password "${DOCKER_REGISTRY_PASSWORD}"
""".stripIndent()
}
}
}
}
}
stage('Check format for PR') {
when { changeRequest target: 'master' }
steps {
container('maven') {
configFileProvider([configFile(fileId: 'maven-settings-nexus-zl', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn formatter:format -B -s $MAVEN_SETTINGS'
script {
def changedLines = sh (script: 'git status --porcelain | wc -l', returnStdout: true)
echo "Git status reports ${changedLines} changed lines after maven format run."
if (changedLines.toInteger() != 0) {
echo 'Some files are formatted incorrectly. Please run `mvn formatter:format` and commit changes.'
sh 'exit 1'
}
}
}
}
}
}
stage('Build release') {
when {
expression { params.release }
}
steps {
container('maven') {
configFileProvider([configFile(fileId: 'maven-settings-nexus-zl', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn install -B -s $MAVEN_SETTINGS'
}
}
}
}
stage('Build & deploy master') {
when {
expression { !params.release && env.BRANCH_NAME == 'master' }
}
steps {
container('maven') {
configFileProvider([configFile(fileId: 'maven-settings-nexus-zl', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn deploy -B -s $MAVEN_SETTINGS'
}
}
}
}
stage('Build & deploy branch') {
when {
expression { !params.release && env.BRANCH_NAME != 'master' }
}
environment {
escaped_branch = currentBranch.toLowerCase().replaceAll('/', '_')
}
steps {
container('maven') {
configFileProvider([configFile(fileId: 'maven-settings-nexus-zl', variable: 'MAVEN_SETTINGS')]) {
sh """
mvn deploy -B -s $MAVEN_SETTINGS -Dtalend_snapshots=https://nexus-smart-branch.datapwn.com/nexus/content/repositories/dev_branch_snapshots/branch_${escaped_branch} -Dtalend_snapshots_deployment=https://artifacts-oss.talend.com/nexus/content/repositories/dev_branch_snapshots/branch_${escaped_branch}
"""
}
}
}
}
stage("Release") {
when {
expression { params.release }
}
steps {
withCredentials([gitCredentials, jiraCredentials]) {
container('maven') {
configFileProvider([configFile(fileId: 'maven-settings-nexus-zl', variable: 'MAVEN_SETTINGS')]) {
sh """
git config --global push.default current
git checkout ${env.BRANCH_NAME}
git pull --tags
mvn -B -s $MAVEN_SETTINGS -Darguments='-P release-notes -DskipTests -Duser=${JIRA_LOGIN} -Dpassword=${JIRA_PASSWORD} -Dversion=${params.release_version} -Doutput=.' -Dtag=${params.release_version} -DreleaseVersion=${params.release_version} -DdevelopmentVersion=${params.next_version} release:prepare install
cd releases/
git add -A .
git commit -m "chore(release) Add ${params.release_version} release notes"
cat ${params.release_version}.adoc
git push
git push --tags
cd ..
mvn -e -B -s $MAVEN_SETTINGS -Darguments='-DskipTests' -DlocalCheckout=true -Dusername=${GIT_LOGIN} -Dpassword=${GIT_PASSWORD} release:perform
"""
}
}
}
slackSend(
color: "GREEN",
channel: "eng-daikon",
message: "Daikon version ${params.release_version} released. (next version: ${params.next_version}) <https://github.com/Talend/daikon/blob/${env.BRANCH_NAME}/releases/${params.release_version}.adoc|${params.release_version} release notes>"
)
}
}
}
post {
always {
junit testResults: '**/target/surefire-reports/*.xml', allowEmptyResults: true
}
}
}