-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSprintProcessJenkinsfile
121 lines (101 loc) · 3.76 KB
/
SprintProcessJenkinsfile
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
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 = 'master'
def newVersion
def server = Artifactory.server 'ART'
def rtMaven = Artifactory.newMavenBuild()
def buildInfo
// Asking user if he wants to start a new sprint, user will choose either proceed or abort
stage('checkout') {
input 'Do you want to start a new Sprint?'
dir(branch) {
checkout([$class: 'GitSCM',
branches: [
[name: branch]
],
userRemoteConfigs: [
[url: 'git@github.com:mosip/mosip.git', credentialsId: 'fd9c5f45-e6ac-45ea-b345-f6fbeb303044']
]
])
}
}
// updating the pom versions to a new version inputed by user and removing '-snapshot'
stage('update-versions') {
dir(branch) {
pom = readMavenPom file: 'pom.xml'
version = pom.version
suggestedValue = pom.version.replace("-SNAPSHOT", "")
String[] st = suggestedValue.split("\\.");
int n = Integer.parseInt(st[1]) + 1;
suggestedValue = st[0] + "." + n + ".0";
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 -DskipTests', buildInfo: buildInfo
}
stage('----------- Publish build info -------------') {
/*
Publishing build info to Artifcatory (JFrog)
*/
server.publishBuildInfo buildInfo
}
stage('GIT - Create new branch') {
dir(branch) {
sh "git checkout -b ${newVersion}"
sh "git add ."
sh "git commit -m 'new branch created'"
sshagent(['fd9c5f45-e6ac-45ea-b345-f6fbeb303044']) {
sh "git push origin ${newVersion}"
}
}
// Setting global environment variable for Branch name
echo "Setting global variable NEXT_BRANCH_NAME to "+newVersion
createGlobalEnvironmentVariables("NEXT_BRANCH_NAME",newVersion)
}
}
// function which will configure Jenkins global variable
public createGlobalEnvironmentVariables(String key, String value) {
Jenkins instance = Jenkins.getInstance();
DescribableList < NodeProperty <?> , NodePropertyDescriptor > globalNodeProperties = instance.getGlobalNodeProperties();
List < EnvironmentVariablesNodeProperty > envVarsNodePropertyList = globalNodeProperties.getAll(EnvironmentVariablesNodeProperty.class);
EnvironmentVariablesNodeProperty newEnvVarsNodeProperty = null;
EnvVars envVars = null;
if (envVarsNodePropertyList == null || envVarsNodePropertyList.size() == 0) {
newEnvVarsNodeProperty = new hudson.slaves.EnvironmentVariablesNodeProperty();
globalNodeProperties.add(newEnvVarsNodeProperty);
envVars = newEnvVarsNodeProperty.getEnvVars();
} else {
envVars = envVarsNodePropertyList.get(0).getEnvVars();
}
envVars.put(key, value)
instance.save()
}