#!/usr/bin/env groovy void call(Map config = [:], Closure body) { Map defaults = [ saveArtifaces: false, buildTest: 'Makefile', buildCmd: 'make all', stepName: 'Build' ] Map runConfig = defaults + config stage(runConfig.stepName) { echo makeStepBanner(runConfig.stepName) if (runConfig.saveArtifacts) { assert runConfig.artifacts : 'Error: saveArtifacts is set to true; must specify artifacts!' } if ( fileExists(runConfig.buildTest)) { sh """ ${runConfig.buildCmd} """ } else { error("ERROR: File ${runConfig.buildTest} does not exist in workspace.") } if (runConfig.saveArtifacts) { artifactsList = runConfig.artifacts.inspect().replaceAll('[\\[\\]\'\"]', '') archiveArtifacts artifacts: artifactsList, followSymlinks: false } body() } }