From cea3844edfb6f83419d970ed9a28cfec8209b4b2 Mon Sep 17 00:00:00 2001 From: Jim Nicholson Date: Wed, 7 Feb 2024 00:46:21 -0800 Subject: [PATCH] Some new stuff to try --- src/com/thejimnicholson/Versioner.groovy | 6 +++++ vars/buildStep.groovy | 34 +++++++++++++----------- vars/checkoutStep.groovy | 12 +++++++-- vars/getCurrentTag.groovy | 11 +++++++- 4 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 src/com/thejimnicholson/Versioner.groovy diff --git a/src/com/thejimnicholson/Versioner.groovy b/src/com/thejimnicholson/Versioner.groovy new file mode 100644 index 0000000..35f4a69 --- /dev/null +++ b/src/com/thejimnicholson/Versioner.groovy @@ -0,0 +1,6 @@ + +class Versioner { + + + +} \ No newline at end of file diff --git a/vars/buildStep.groovy b/vars/buildStep.groovy index 2c282de..57710bc 100644 --- a/vars/buildStep.groovy +++ b/vars/buildStep.groovy @@ -1,24 +1,28 @@ #!/usr/bin/env groovy -void call(Map config = [:]) { +void call(Map config = [:], Closure body) { Map defaults = [ saveArtifaces: false, buildTest: 'Makefile', - buildCmd: 'make all' + buildCmd: 'make all', + stepName: 'Build' ] Map runConfig = defaults + config - 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 + stage(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() } } diff --git a/vars/checkoutStep.groovy b/vars/checkoutStep.groovy index 88d620d..8043204 100644 --- a/vars/checkoutStep.groovy +++ b/vars/checkoutStep.groovy @@ -1,5 +1,13 @@ #!/usr/bin/env groovy -void call() { - checkout scm +void call(Map config = [:], Closure body) { + Map defaults = [ + stepName: 'Checkout', + useJobSCM: true + ] + runDefaults = defaults + config + stage(runConfig.stepName) { + checkout scm + body() + } } diff --git a/vars/getCurrentTag.groovy b/vars/getCurrentTag.groovy index 71776aa..52ca9b5 100644 --- a/vars/getCurrentTag.groovy +++ b/vars/getCurrentTag.groovy @@ -10,5 +10,14 @@ String call(Map config = [:]) { script: "git describe --tags --always --dirty=${runConfig.dirtyFlag}", returnStdout: true ).trim() - return gitTag + + gitHash = sh( + script: 'git rev-parse --short HEAD', + returnStdout: true + ).trim() + + runConfig.tag = gitTag + runConfig.hash = gitHash + + return runConfig }