This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathJenkinsfile
143 lines (123 loc) · 4.78 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
#!/usr/bin/env groovy
/**
* This is a <b>very</b> simple implementation of handling rpms and a puppet only build in the very same Jenkinsfile.</br>
* In order to have the stages displayed properly in the Jenkins UI you should have the same stages for either way. If stage names differ between job-run n-1 and n
* the main page of the job will only display the current job run rather than the cool history of the last runs in the pipeline execution table.</br>
*/
node {
SCRIPTS_DIR = "${WORKSPACE}/scripts"
GENERAL_CONFIG_FILE = "${SCRIPTS_DIR}/script-env-vars.groovy"
RHEL_VERSION_SPECIFIC_CONFIG_FILE_SUFFIX = "-script-env-vars-rpm.groovy"
RHEL_VERSION_SPECIFIC_PUPPEPT_ONLY_CONFIG_FILE_SUFFIX= "-script-env-vars-puppet-only.groovy"
runScriptVerbose = params.VERBOSE ? true : false
bashExec = runScriptVerbose ? '/bin/bash -x' : '/bin/bash'
rhelVersionSpecificConfigFile = "${SCRIPTS_DIR}/${params.RHEL_VERSION}" + RHEL_VERSION_SPECIFIC_CONFIG_FILE_SUFFIX
rhelVersionSpecificPuppetOnlyConfigFile = "${SCRIPTS_DIR}/${params.RHEL_VERSION}" + RHEL_VERSION_SPECIFIC_PUPPEPT_ONLY_CONFIG_FILE_SUFFIX
specificConfigFile = params.PUPPET_ONLY == true ? rhelVersionSpecificPuppetOnlyConfigFile : rhelVersionSpecificConfigFile
isInErrorState = false
if (params.CLEAN_WORKSPACE == true) {
deleteDir()
}
def stageCheckout = {
dir('scripts') {
git credentialsId: "${params.CREDENTIALS_ID_SOE_CI_IN_JENKINS}", branch: "${params.SOE_CI_BRANCH}", poll: false, url: "${params.SOE_CI_REPO_URL}"
}
dir('soe') {
git credentialsId: "${params.CREDENTIALS_ID_ACME_SOE_IN_JENKINS}", branch:"${params.ACME_SOE_BRANCH}", poll: false, url: "${params.ACME_SOE_REPO_URL}"
}
}
executeStage(stageCheckout, 'Checkout from Git')
def stageLoadConfig = {
checkThatConfigFilesExist()
environmentVariables()
}
executeStage(stageLoadConfig, 'check that config files exist')
def stageBuild = {
executeScript("${SCRIPTS_DIR}/rpmbuild.sh ${WORKSPACE}/soe/rpms", true)
executeScript("${SCRIPTS_DIR}/kickstartbuild.sh ${WORKSPACE}/soe/kickstarts", true)
executeScript("${SCRIPTS_DIR}/puppetbuild.sh ${WORKSPACE}/soe/puppet", false)
}
executeStage(stageBuild, 'build')
def stagePushToSat = {
executeScript("${SCRIPTS_DIR}/rpmpush.sh ${WORKSPACE}/artefacts", true)
executeScript("${SCRIPTS_DIR}/puppetpush.sh ${WORKSPACE}/artefacts", false)
executeScript("${SCRIPTS_DIR}/kickstartpush.sh ${WORKSPACE}/artefacts", true)
}
executeStage(stagePushToSat, 'push to Satellite')
def stagePubAndPromote = {
executeScript("${SCRIPTS_DIR}/publishcv.sh", false)
executeScript("${SCRIPTS_DIR}/capsule-sync-check.sh", false)
}
executeStage(stagePubAndPromote, 'publish and promote CV')
def stagePrepVms = {
if (params.REBUILD_VMS == true) {
executeScript("${SCRIPTS_DIR}/buildtestvms.sh")
} else {
executeScript("${SCRIPTS_DIR}/starttestvms.sh")
}
}
executeStage(stagePrepVms, 'prepare VMs')
def stageRunTests = {
executeScript("${SCRIPTS_DIR}/pushtests.sh")
step([$class: "TapPublisher", testResults: "test_results/*.tap", ])
}
executeStage(stageRunTests, 'run tests')
def stagePowerOff = {
if (params.POWER_OFF_VMS_AFTER_BUILD == true) {
executeScript("${SCRIPTS_DIR}/powerofftestvms.sh")
} else {
println "test VMs are not shut down as per passed configuration"
}
}
executeStage(stagePowerOff, 'power off VMs')
def stageCleanup = {
executeScript("${SCRIPTS_DIR}/cleanup.sh")
}
executeStage(stageCleanup, 'cleanup')
}
def executeStage(Closure closure, String stageName) {
stage(stageName) {
if ( isInErrorState == false) {
try {
closure()
} catch(e) {
isInErrorState = true
error(e.getMessage())
currentBuild.result = 'FAILURE'
}
}
}
}
/**
* depending on the chosen value of the param <code>RHEL_VERSION</code>,
* we need to check that the config files exist rather than to wait for the pipeline
* to reach the point where it needs those configs and then fails.
*/
def checkThatConfigFilesExist() {
filesMissing = false
errorMessage = "The following config files are missing:"
[GENERAL_CONFIG_FILE, specificConfigFile].each { fileName ->
if (fileExists("${fileName}") == false) {
filesMissing = true
errorMessage = errorMessage + " ${fileName}"
}
}
if (filesMissing) {
error(errorMessage)
}
}
def environmentVariables() {
[GENERAL_CONFIG_FILE, specificConfigFile].each { fileName ->
load "${fileName}"
}
}
def executeScript(String bashArguments) {
executeScript("$bashArguments", false)
}
def executeScript(String bashArguments, boolean rpmRelevant) {
if (rpmRelevant && params.PUPPET_ONLY == true) {
println "Skipping, puppet-only build."
} else {
sh "${bashExec} $bashArguments"
}
}