Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Commit

Permalink
Added failure closure for archSlave
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypoulz authored Nov 28, 2017
1 parent 71b9bb0 commit a9fe2d0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions vars/archSlave.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
*
* Runs closure body on a multi-arch slave for each arch in params.ARCHES.
*
* @param body Closure that takes a two String parameters representing the name and architecture of the slave.
* @param onSuccess Closure that takes two parameters representing the name String and the architecture String of the slave.
* @param onFailure Closure that takes two parameters representing the Exception that occured and the architecture String of the slave.
* @param runOnSlave Boolean that specificies whether the
* closure should be run on directly on the provisioned slave.
*/
def call(Closure body, def Boolean runOnSlave = true) {
def call(def Closure onSuccess = null, def Closure onFailure = null, def Boolean runOnSlave = true) {
arches(
{ a ->
def String arch = new String(a)
Expand All @@ -26,17 +27,19 @@ def call(Closure body, def Boolean runOnSlave = true) {
throw new Exception(slave.error)
}

if (onSuccess == null) return

if (runOnSlave) {
node(slave.name) {
body(slave.name, slave.arch)
onSuccess(slave.name, slave.arch)
}
return
}

body(slave.name, slave.arch)
onSuccess(slave.name, slave.arch)
} catch (e) {
// This is just a wrapper step to ensure that teardown is run upon failure
println(e)
if (onFailure == null) return
onFailure(e, slave.arch)
} finally {
// Ensure teardown runs before the pipeline exits
stage ('Teardown Slave') {
Expand Down

0 comments on commit a9fe2d0

Please sign in to comment.