-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
98 lines (78 loc) · 3.14 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
#!/usr/bin/env groovy
openshift.withCluster() { // Use "default" cluster or fallback to OpenShift cluster detection
echo "Hello from the project running Jenkins: ${openshift.project()}"
//Create template with maven settings.xml, so we have credentials for nexus
podTemplate(
inheritFrom: 'maven',
cloud: 'openshift', //cloud must be openshift
volumes: [ //mount the settings.xml
secretVolume(mountPath: '/etc/m2', secretName: 'maven-settings')
]) {
String projectName = encodeName("${JOB_NAME}")
echo "name=${projectName}"
try {
//GO to a node with maven and settings.xml
node(POD_LABEL) {
//Do not use concurrent builds
properties([disableConcurrentBuilds()])
def mvnCmd = "mvn -s /etc/m2/settings.xml --batch-mode"
//settings.xml could be in ~/.m2/settings.xml but I did not want to find the username and home
stage('checkout') {
checkout scm
}
stage('Mvn clean package') {
sh "${mvnCmd} -PallTests clean package"
}
stage('Analyze build results') {
recordIssues aggregatingResults: true,
tools: [java(),
javaDoc(),
mavenConsole(),
taskScanner(highTags:'FIXME', normalTags:'TODO', includePattern: '**/*.java', excludePattern: 'target/**/*')]
}
stage('Push to Nexus (if Master)') {
sh 'env'
echo "Branch name ${env.BRANCH_NAME}"
if ("${env.BRANCH_NAME}" == 'master') {
sh "${mvnCmd} deploy -DskipTests=true"
} else {
echo "Branch ${env.BRANCH_NAME} is not master, so no mvn deploy"
}
}
}
} catch (e) {
currentBuild.result = 'FAILURE'
throw e
}
}
}
private void recreateProject(String projectName) {
echo "Delete the project ${projectName}, ignore errors if the project does not exist"
try {
openshift.selector("project/${projectName}").delete()
openshift.selector("project/${projectName}").watch {
echo "Waiting for the project ${projectName} to be deleted"
return it.count() == 0
}
} catch (e) {
}
//
// //Wait for the project to be gone
// sh "until ! oc get project ${projectName}; do date;sleep 2; done; exit 0"
echo "Create the project ${projectName}"
openshift.newProject(projectName)
}
/**
* Encode the jobname as a valid openshift project name
* @param jobName the name of the job
* @return the jobname as a valid openshift project name
*/
private static String encodeName(groovy.lang.GString jobName) {
def name = jobName
.replaceAll("\\s", "-")
.replaceAll("_", "-")
.replace("/", '-')
.replaceAll("^openshift-", "")
.toLowerCase()
return name
}