Skip to content

Instantly share code, notes, and snippets.

@alisade
Created April 1, 2021 15:07
Show Gist options
  • Save alisade/42c681998d2e5d7867e80be645b6913f to your computer and use it in GitHub Desktop.
Save alisade/42c681998d2e5d7867e80be645b6913f to your computer and use it in GitHub Desktop.
jenkins parallel build agent
// Job == agent-build_pipeline
// build agent for linux/windows
currentBuild.description = env.TAG
def WORKER='worker-large'
def OS = [ 'redhat', 'debian' ]
def ARCH = [ '64' ]
def pipeline_branches = [:]
def JB='./jenkins/build'
def jbuild = { sh "bash ${JB}/build.sh" }
def provision = { sh "bash ${JB}/provision.sh" }
def sign = { sh "bash ${JB}/sign.sh" }
def cleanup = { sh "bash ${JB}/cleanup.sh" }
switch ( env.TAG ) {
case ~ /.*windows.*/ :
WORKER='worker-windows'
OS = ['windows']
ARCH = [ '64' ]
jbuild = {}
provision = { bat "${JB}/provision.bat" }
sign = {}
cleanup = {}
break
}
for ( os in OS )
for ( arch in ARCH )
pipeline_branches["${os}-${arch}"] = build_agent(os, arch, env.TAG,
jbuild, provision, sign,
cleanup, WORKER)
parallel pipeline_branches
def build_agent(os, arch, tag, jbuild, provision, sign, cleanup, worker) {
return {
node(worker) {
withEnv(["TAG=${tag}",
"OS=${os}",
"ARCH=${arch}"
]) {
stage("${os}-${arch}-checkout") {
checkout scm
}
stage("${os}-${arch}-cleanup") {
cleanup()
}
stage("${os}-${arch}-build") {
jbuild()
}
stage("${os}-${arch}-provision") {
provision()
}
stage("${os}-${arch}-sign") {
sign()
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment