pipelineUtils/vars/buildStep.groovy
2024-02-07 02:25:41 -08:00

30 lines
942 B
Groovy

#!/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 "${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()
}
}