-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJenkinsfile_release
More file actions
179 lines (172 loc) · 8.12 KB
/
Copy pathJenkinsfile_release
File metadata and controls
179 lines (172 loc) · 8.12 KB
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
pipeline {
agent {
kubernetes {
yaml '''
apiVersion: v1
kind: Pod
metadata:
name: qlack
namespace: jenkins
spec:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 50
podAffinityTerm:
labelSelector:
matchExpressions:
- key: jenkins/jenkins-jenkins-agent
operator: In
values:
- "true"
topologyKey: kubernetes.io/hostname
securityContext:
runAsUser: 0
runAsGroup: 0
containers:
- name: qlack-release
image: eddevopsd2/maven-java-npm-docker:mvn3.8.5-jdk17-node18.16-go1.20-docker
volumeMounts:
- name: maven
mountPath: /root/.m2/
subPath: Qlack-Java
tty: true
securityContext:
privileged: true
runAsUser: 0
runAsGroup: 0
imagePullSecrets:
- name: regcred
restartPolicy: OnFailure
volumes:
- name: maven
persistentVolumeClaim:
claimName: maven-nfs-pvc
'''
workspaceVolume persistentVolumeClaimWorkspaceVolume(claimName: 'workspace-nfs-pvc', readOnly: false)
}
}
options {
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '10'))
timeout(time: 3, unit: 'HOURS')
}
stages {
stage ('Prompt for Input') {
steps {
script {
env.RELEASE_VERSION = input message: 'Release version:',
parameters: [string(defaultValue: '',
description: 'Attention: Do not push to git until this job finishes.',
name: 'Release version')]
env.NEXT_DEV_VERSION = input message: 'Snapshot version:',
parameters: [string(defaultValue: '',
description: '',
name: 'Next development version')]
}
}
}
stage('Clone project') {
steps{
container (name: 'qlack-release') {
withCredentials([usernamePassword(credentialsId: 'Jenkins-Github-token',
usernameVariable: 'Username',
passwordVariable: 'Password')]){
sh '''
git config --global user.email "devops-d2@eurodyn.com"
git config --global user.name "$Username"
git clone https://$Username:$Password@github.com/qlack/QLACK-Base-Application.git
'''
}
}
}
}
stage('Updates for release version') {
steps{
container (name: 'qlack-release') {
sh '''
cd QLACK-Base-Application/qlack-base-application-server
mvn versions:set -DnewVersion=$RELEASE_VERSION
mvn versions:commit
cd ../qlack-base-application-ui
sed -i 's|\"version\":.*$|\"version\": \"'$RELEASE_VERSION'\",|' package.json
awk -v sb=' \"name\": \"qlack-base-application-ui\",\n \"version\": \"'$RELEASE_VERSION'\",' '/"name": "qlack-base-application-ui",/,/"version":.*/ { if ( $0 ~ /"version":.*/ ) print sb; next } 1' package-lock.json > temp.json && cp -f temp.json package-lock.json && rm temp.json
cd ..
sed -i "s|qlack/qba-ui:.*$|qlack/qba-ui:$RELEASE_VERSION|" docker-compose.yml
sed -i "s|qlack/qba-server:.*$|qlack/qba-server:$RELEASE_VERSION|" docker-compose.yml
'''
}
}
}
stage ('Push changes for release version') {
steps{
container (name: 'qlack-release') {
withCredentials([usernamePassword(credentialsId: 'Jenkins-Github-token',
usernameVariable: 'Username',
passwordVariable: 'Password')]){
sh '''
cd QLACK-Base-Application
git remote set-url origin https://$Username:$Password@github.com/qlack/QLACK-Base-Application.git
git commit -a -m "release: prepare release $RELEASE_VERSION for QLACK-Base-Application"
git tag -a $RELEASE_VERSION -m "$RELEASE_VERSION"
git push https://$Username:$Password@github.com/qlack/QLACK-Base-Application.git HEAD:master --tags
'''
}
}
}
}
stage('Updates for next development version') {
steps{
container (name: 'qlack-release') {
sh '''
cd QLACK-Base-Application/qlack-base-application-server
mvn versions:set -DnewVersion=$NEXT_DEV_VERSION
mvn versions:commit
cd ../qlack-base-application-ui
sed -i 's|\"version\":.*$|\"version\": \"'$NEXT_DEV_VERSION'\",|' package.json
awk -v sb=' \"name\": \"qlack-base-application-ui\",\n \"version\": \"'$NEXT_DEV_VERSION'\",' '/"name": "qlack-base-application-ui",/,/"version":.*/ { if ( $0 ~ /"version":.*/ ) print sb; next } 1' package-lock.json > temp.json && cp -f temp.json package-lock.json && rm temp.json
'''
}
}
}
stage ('Push changes for next development version') {
steps{
container (name: 'qlack-release') {
withCredentials([usernamePassword(credentialsId: 'Jenkins-Github-token',
usernameVariable: 'Username',
passwordVariable: 'Password')]){
sh '''
cd QLACK-Base-Application
git remote set-url origin https://$Username:$Password@github.com/qlack/QLACK-Base-Application.git
git commit -a -m "release: prepare for next development iteration $NEXT_DEV_VERSION for QLACK-Base-Application"
git push https://$Username:$Password@github.com/qlack/QLACK-Base-Application.git HEAD:master
'''
}
}
}
}
}
post {
success {
rocketSend avatar: "http://d2-np.eurodyn.com/jenkins/jenkins.png", channel: 'qlack', message: "Version ${env.RELEASE_VERSION} of QLACK-Base-Application has been released :rocket:", rawMessage: true
}
}
}
@NonCPS
def getChangeString(maxMessages) {
MAX_MSG_LEN = 100
def changeString = ""
def changeLogSets = currentBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length && i + j < maxMessages; j++) {
def entry = entries[j]
truncated_msg = entry.msg.take(MAX_MSG_LEN)
changeString += "*${truncated_msg}* _by author ${entry.author}_\n"
}
}
if (!changeString) {
changeString = " There have not been any changes since the last build"
}
return changeString
}