diff --git a/test/groovy/templates/PiperPipelineStageInitTest.groovy b/test/groovy/templates/PiperPipelineStageInitTest.groovy index 3dce8d1f6..0948486d5 100644 --- a/test/groovy/templates/PiperPipelineStageInitTest.groovy +++ b/test/groovy/templates/PiperPipelineStageInitTest.groovy @@ -122,7 +122,7 @@ class PiperPipelineStageInitTest extends BasePiperTest { stashSettings: 'com.sap.piper/pipeline/stashSettings.yml' ) - assertThat(stepsCalled, hasItems('checkout', 'setupCommonPipelineEnvironment', 'piperInitRunStageConfiguration', 'artifactSetVersion', 'pipelineStashFilesBeforeBuild')) + assertThat(stepsCalled, hasItems('checkout', 'setupCommonPipelineEnvironment', 'piperInitRunStageConfiguration', 'artifactPrepareVersion', 'pipelineStashFilesBeforeBuild')) assertThat(stepsCalled, not(hasItems('slackSendNotification'))) } @@ -176,7 +176,7 @@ class PiperPipelineStageInitTest extends BasePiperTest { 'checkout', 'setupCommonPipelineEnvironment', 'piperInitRunStageConfiguration', - 'artifactSetVersion', + 'artifactPrepareVersion', 'slackSendNotification', 'pipelineStashFilesBeforeBuild' )) @@ -211,7 +211,7 @@ class PiperPipelineStageInitTest extends BasePiperTest { 'checkout', 'setupCommonPipelineEnvironment', 'piperInitRunStageConfiguration', - 'artifactSetVersion', + 'artifactPrepareVersion', 'pipelineStashFilesBeforeBuild' )) } diff --git a/vars/piperPipelineStageInit.groovy b/vars/piperPipelineStageInit.groovy index 91b586e4a..1b88ab12c 100644 --- a/vars/piperPipelineStageInit.groovy +++ b/vars/piperPipelineStageInit.groovy @@ -189,7 +189,6 @@ void call(Map parameters = [:]) { echo "[${STEP_NAME}] GitHub labels could not be retrieved from Pull Request, please make sure that credentials are maintained on multi-branch job." } - setPullRequestStageStepActivation(script, config, prActions) } @@ -197,15 +196,19 @@ void call(Map parameters = [:]) { if (parameters.script.commonPipelineEnvironment.configuration.runStep?.get('Init')?.slackSendNotification) { slackSendNotification script: script, message: "STARTED: Job <${env.BUILD_URL}|${URLDecoder.decode(env.JOB_NAME, java.nio.charset.StandardCharsets.UTF_8.name())} ${env.BUILD_DISPLAY_NAME}>", color: 'WARNING' } - if (config.inferBuildTool && env.ON_K8S) { - // We set dockerImage: "" for the K8S case to avoid the execution of artifactPrepareVersion in a K8S Pod. - // In addition, a mvn executable is available on the Jenkins instance which can be used directly instead of executing the command in a container. - artifactPrepareVersion script: script, buildTool: buildTool, dockerImage: "" - } else if (config.inferBuildTool) { - artifactPrepareVersion script: script, buildTool: buildTool - } else { - artifactSetVersion script: script + Map prepareVersionParams = [script: script] + if (config.inferBuildTool) { + prepareVersionParams.buildTool = buildTool } + if (env.ON_K8S) { + // We force dockerImage: "" for the K8S case to avoid the execution of artifactPrepareVersion in a K8S Pod. + // Since artifactPrepareVersion may need the ".git" folder in order to push a tag, it would need to be part of the stashing. + // There are however problems with tar-ing this folder, which results in a failure to copy the stash back -- without a failure of the pipeline. + // This then also has the effect that any changes made to the build descriptors by the step (updated version) are not visible in the relevant stashes. + // In addition, a mvn executable is available on the Jenkins instance which can be used directly instead of executing the command in a container. + prepareVersionParams.dockerImage = "" + } + artifactPrepareVersion prepareVersionParams } pipelineStashFilesBeforeBuild script: script }