Some new stuff to try

This commit is contained in:
Jim Nicholson 2024-02-07 00:46:21 -08:00
parent 1a1d694001
commit cea3844edf
4 changed files with 45 additions and 18 deletions

View File

@ -0,0 +1,6 @@
class Versioner {
}

View File

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

View File

@ -1,5 +1,13 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
void call() { void call(Map config = [:], Closure body) {
checkout scm Map defaults = [
stepName: 'Checkout',
useJobSCM: true
]
runDefaults = defaults + config
stage(runConfig.stepName) {
checkout scm
body()
}
} }

View File

@ -10,5 +10,14 @@ String call(Map config = [:]) {
script: "git describe --tags --always --dirty=${runConfig.dirtyFlag}", script: "git describe --tags --always --dirty=${runConfig.dirtyFlag}",
returnStdout: true returnStdout: true
).trim() ).trim()
return gitTag
gitHash = sh(
script: 'git rev-parse --short HEAD',
returnStdout: true
).trim()
runConfig.tag = gitTag
runConfig.hash = gitHash
return runConfig
} }