Skip to content

Commit

Permalink
CI: Jenkinsfile - clean up docker images created in packaging stage
Browse files Browse the repository at this point in the history
  • Loading branch information
henryborchers committed Dec 6, 2023
1 parent 8defcd5 commit 203ef51
Showing 1 changed file with 22 additions and 39 deletions.
61 changes: 22 additions & 39 deletions ci/jenkins/scripts/packaging.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def getDockerRuntimeArgs(agent){
return ""
}

def getAgent(args, dockerImageName=null){
def getAgent(args){
if (args.agent.containsKey("label")){
return { inner ->
node(args.agent.label){
Expand All @@ -43,12 +43,28 @@ def getAgent(args, dockerImageName=null){
ws{
checkout scm
def dockerImage
dockerImageName = dockerImageName ? dockerImageName: "${currentBuild.fullProjectName}_${getToxEnv(args)}".replaceAll("-", "_").replaceAll('/', "_").replaceAll(' ', "").toLowerCase()
def dockerImageName = "${currentBuild.fullProjectName}_${getToxEnv(args)}_${UUID.randomUUID().toString()}".replaceAll("-", "_").replaceAll('/', "_").replaceAll(' ', "").toLowerCase()
lock("docker build-${env.NODE_NAME}"){
dockerImage = docker.build(dockerImageName, "-f ${args.agent.dockerfile.filename} ${args.agent.dockerfile.additionalBuildArgs} .")
}
dockerImage.inside(dockerArgs){
inner()
try{
dockerImage.inside(dockerArgs){
inner()
}
} finally{
if(isUnix()){
sh(
label: "Untagging Docker Image used",
script: "docker image rm --no-prune ${dockerImage.imageName()}",
returnStatus: true
)
} else {
powershell(
label: "Untagging Docker Image used",
script: "docker image rm --no-prune ${dockerImage.imageName()}",
returnStatus: true
)
}
}
}
}
Expand All @@ -58,36 +74,6 @@ def getAgent(args, dockerImageName=null){
}

def testPkg(args = [:]){
def tox = args['toxExec'] ? args['toxExec']: "tox"
def setup = args['testSetup'] ? args['testSetup']: {
checkout scm
unstash "${args.stash}"
}
def teardown = args['testTeardown'] ? args['testTeardown']: {}

def agentRunner = getAgent(args)
agentRunner {
setup()
try{
findFiles(glob: args.glob).each{
def toxCommand = "${tox} --installpkg ${it.path} -e ${getToxEnv(args)}"
if(isUnix()){
sh(label: "Testing tox version", script: "${tox} --version")
// toxCommand = toxCommand + " --workdir /tmp/tox"
sh(label: "Running Tox", script: toxCommand)
} else{
bat(label: "Testing tox version", script: "${tox} --version")
toxCommand = toxCommand + " --workdir %TEMP%\\tox"
bat(label: "Running Tox", script: toxCommand)
}
}
} finally{
teardown()
}
}
}

def testPkg2(args = [:]){
def testCommand = args['testCommand'] ? args['testCommand']: {
def distroFiles = findFiles(glob: 'dist/*.tar.gz,dist/*.zip,dist/*.whl')
if (distroFiles.size() == 0){
Expand All @@ -113,7 +99,7 @@ def testPkg2(args = [:]){
def successful = args['post']['success'] ? args['post']['success']: {}
def failure = args['post']['failure'] ? args['post']['failure']: {}
def dockerImageName = args['dockerImageName'] ? args['dockerImageName']: "${currentBuild.fullProjectName}_${getToxEnv(args)}_build".replaceAll("-", "_").replaceAll('/', "_").replaceAll(' ', "").toLowerCase()
def agentRunner = getAgent(args, dockerImageName)
def agentRunner = getAgent(args)
agentRunner {
setup()
try{
Expand All @@ -129,7 +115,6 @@ def testPkg2(args = [:]){
}

def buildPkg(args = [:]){
def dockerImageName = "${currentBuild.fullProjectName}_${getToxEnv(args)}_build".replaceAll("-", "_").replaceAll('/', "_").replaceAll(' ', "").toLowerCase()
def setup = args['buildSetup'] ? args['buildSetup']: {
checkout scm
}
Expand All @@ -145,8 +130,7 @@ def buildPkg(args = [:]){
}
def retries = args['retries'] ? args['retries'] : 1
retry(retries){
def agentRunner = getAgent(args, dockerImageName)
agentRunner {
getAgent(args) {
setup()
try{
buildCmd()
Expand All @@ -162,6 +146,5 @@ def buildPkg(args = [:]){
}
return [
testPkg: this.&testPkg,
testPkg2: this.&testPkg2,
buildPkg: this.&buildPkg
]

0 comments on commit 203ef51

Please sign in to comment.