forked from gitter-badger/daikon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
171 lines (161 loc) · 5.4 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
def slackChannel = 'daikon'
def gitCredentials = usernamePassword(
credentialsId: 'github-credentials',
passwordVariable: 'GIT_PASSWORD',
usernameVariable: 'GIT_LOGIN')
def jiraCredentials = usernamePassword(
credentialsId: 'jira-credentials',
passwordVariable: 'JIRA_PASSWORD',
usernameVariable: 'JIRA_LOGIN')
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'
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: maven
image: jenkinsxio/builder-maven:0.1.211
command:
- cat
tty: true
volumeMounts:
- name: docker
mountPath: /var/run/docker.sock
- name: m2
mountPath: /root/daikon/.m2/repository
volumes:
- name: docker
hostPath:
path: /var/run/docker.sock
- name: m2
hostPath:
path: /tmp/jenkins/daikon/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'
}
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('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}
mvn -B -s $MAVEN_SETTINGS -Darguments='-DskipTests' -Dtag=${params.release_version} -DreleaseVersion=${params.release_version} -DdevelopmentVersion=${params.next_version} release:prepare
cd releases/
mvn install -B -s $MAVEN_SETTINGS -Duser=${JIRA_LOGIN} -Dpassword=${JIRA_PASSWORD} -Dversion=${params.release_version} -Doutput=.
git add -A .
git commit -m "Add ${params.release_version} release notes"
cat ${params.release_version}.adoc
git push
git push --tags
cd ..
mvn -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/master/releases/${params.release_version}.adoc|${params.release_version} release notes>"
)
}
}
}
post {
always {
junit testResults: '**/target/surefire-reports/*.xml', allowEmptyResults: true
}
}
}