-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPromoteToQAJenkinsFile
134 lines (120 loc) · 4 KB
/
PromoteToQAJenkinsFile
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
import hudson.EnvVars;
import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.slaves.NodeProperty;
import hudson.slaves.NodePropertyDescriptor;
import hudson.util.DescribableList;
import jenkins.model.Jenkins;
node {
def mvnHome = tool name: 'M2_HOME', type: 'maven'
def branch = env.NEXT_BRANCH_NAME
def mosip_config_branch="mosip_config_${branch}"
def newVersion
def server = Artifactory.server 'ART'
def rtMaven = Artifactory.newMavenBuild()
def buildInfo
// Asking user if he wants to promote the code to QA, user will choose either proceed or abort
stage('checkout') {
input 'Do you want to promote the code to QA?'
dir(branch) {
checkout([$class: 'GitSCM',
branches: [
[name: branch]
],
extensions: scm.extensions + [[$class: 'CleanCheckout']],
userRemoteConfigs: [
[url: 'git@github.com:mosip/mosip.git', credentialsId: 'fd9c5f45-e6ac-45ea-b345-f6fbeb303044']
]
])
}
dir(mosip_config_branch) {
checkout([$class: 'GitSCM',
branches: [
[name: branch]
],
extensions: scm.extensions + [[$class: 'CleanCheckout']],
userRemoteConfigs: [
[url: 'git@github.com:mosip/mosip-configuration.git', credentialsId: 'aruna']
]
])
}
}
// updating the pom versions to a new version inputed by user and removing '-snapshot'
stage('update-versions') {
dir(branch) {
sh "git status"
pom = readMavenPom file: 'pom.xml'
version = pom.version
suggestedValue = pom.version
String[] st = suggestedValue.split("\\.");
int n = Integer.parseInt(st[2]) + 1;
suggestedValue = st[0] + "." + st[1] + "."+n;
def userInput = input(
id: 'userInput', message: 'Enter version number',
parameters: [
string(
defaultValue: suggestedValue,
description: 'Previous version in pom.xml is ' + version,
name: 'Version')
])
// Save to variables. Default to empty string if not found.
echo userInput
newVersion = pom.version.replace("${version}", "${userInput}")
sh "${mvnHome}/bin/mvn versions:set -DnewVersion=${newVersion}"
sh "${mvnHome}/bin/mvn versions:commit"
}
}
stage('--------- Artifactory configuration ----------------') {
/*
JFrog artifactory configuration
*/
rtMaven.tool = 'M2_HOME' // Tool name from Jenkins configuration
rtMaven.deployer releaseRepo: 'libs-release-local', snapshotRepo: 'libs-snapshot-local', server: server
rtMaven.resolver releaseRepo: 'libs-release', snapshotRepo: 'libs-snapshot', server: server
buildInfo = Artifactory.newBuildInfo()
buildInfo.env.capture = true
}
stage('---------- mvn-clean-install and push to artifactory ---------------') {
rtMaven.run pom: branch + '/pom.xml', goals: 'clean install -Dspring.cloud.config.label='+branch, buildInfo: buildInfo
}
stage('----------- Publish build info -------------') {
/*
Publishing build info to Artifcatory (JFrog)
*/
server.publishBuildInfo buildInfo
}
stage('GIT - Push the code and Create new tag') {
dir(branch) {
// jenkins git plugin detaches the head after checking out the code, stashing the changes to check out branch code
sh "git stash"
// checking out branch
sh "git checkout $branch"
// applying stashed changes to branch
sh "git stash apply"
sh "git add ."
// clearing the stash
sh "git stash clear"
// commiting changes to branch
sh "git commit -m 'MOS-14569 updating versions and tagging the code for giving it to QA'"
sshagent(['fd9c5f45-e6ac-45ea-b345-f6fbeb303044']) {
sh "git push origin $branch"
}
// creating a git tag
sh "git tag ${newVersion}"
// pushing tag to github
sshagent(['fd9c5f45-e6ac-45ea-b345-f6fbeb303044']) {
sh "git push origin ${newVersion}"
}
}
dir(mosip_config_branch){
sh "git checkout ${branch}"
sh 'git status'
sh 'ls'
sh "git tag ${newVersion}"
sshagent(['aruna']) {
sh "git push origin ${newVersion}"
}
}
// Clean the workspace to avoid GIT conflicts when next time this pipeline is triggered
cleanWs()
}
}