Skip to content
This repository was archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
Jenkins pipeline (#117)
Browse files Browse the repository at this point in the history
* Introdcue pipeline as code

* adjusted copy of buildtestvms.sh

* introduce sleep flag to puppet-done-test.sh

* added one forced puppet run before we start waiting

* remove workspace cleanup plugin specific step and use deleteDir instead

* disable systemd-nspawn in mock. Fixes #74

* Cleanups 20170914 (#78)

* info -> inform

info is a shell command, so switch to infrom as function name
for printing info.

* first version of capsule sync check

* explain why pushtests.sh can take a long time

* remove superfuous spaces in README.md

* fix typo in variable name

* echo before sleep when poking SUT

* fixup, had one inform line twice

* wait for both ContentView and Repository syncs

* Issue 87 (#89)

* remove note to disable SELinux. Closes #87

* fixup, typo

* fixes #25

* use capsule-sync-check.sh in Jenkinsfile

* introduce timeouts for puppet-done-test

- should fix Issue #97
- working fine when tested at $current_customer

* Wait for build of test VMs to end (#96)

* make buildtestvms.sh wait for SUT to exit build state

* sleep 10 -> 15 and shorted log output

* only check every minute on an installing VM

* fixup: typo

* split up prep and test stages

* add config option for rhel version

* rename from elX to rhel-x, add documentation for pipeline in general

* fixed typo in markdown

* rhel-version param is defined in pipeline job, removed param from config.xml for polling job

* minor corrections after proofreading

* Issue 106: Always display all stages in jenkins' (classic) stage view

* fixed typo

* Satellite 6.3 fixed Bug 1417976 remove Sat 6.2 work-around in buildtestvms.sh

* adjust hammer command for Sat 6.3.2

* fixup, clarify log message

* minor documentation fix

* fixed markdown and adjusted headers

* add lost statement that the jenkins user has to own the job config file

* forgotten info -> infrom fixed in two files

* use the intended CV for pipeline job

* Sat 6.3, 6.4 and 6.5 added to readme

* new path for hammer CLI config

* adjust install guide link to Sat 6.5 one

* link to latest hammer cli config docs

* allow promote environment out of sequence
  • Loading branch information
pcfe authored and nstrug committed Aug 16, 2019
1 parent c519f80 commit abbb35a
Show file tree
Hide file tree
Showing 13 changed files with 619 additions and 262 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
143 changes: 143 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,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"
}
}
Loading

0 comments on commit abbb35a

Please sign in to comment.