From 3b45fbd2ea4cd7c28b17be1063b529ae7510b0ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Le=20Meur?= <91831478+lemeurherve@users.noreply.github.com> Date: Tue, 18 Jun 2024 18:29:38 +0200 Subject: [PATCH] chore: improve env var scopes and retrieve `VERSION` in build.ps1 (#424) * chore: improve env var scopes and retrieve `VERSION` as env var in build.ps1 * remove extraneous space --- Jenkinsfile | 24 ++++++++++++------------ build.ps1 | 4 ++++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 118113f6..d3b66802 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,13 +1,13 @@ def agentSelector(String imageType) { - // Image type running on a Linux agent + // Linux agent if (imageType == 'linux') { return 'linux' } - // Image types running on a Windows Server Core 2022 agent + // Windows Server Core 2022 agent if (imageType.contains('2022')) { return 'windows-2022' } - // Remaining image types running on a Windows Server Core 2019 agent: (nanoserver|windowservercore)-(1809|2019) + // Windows Server Core 2019 agent (for nanoserver 1809 & ltsc2019 and for windowservercore ltsc2019) return 'windows-2019' } @@ -20,6 +20,9 @@ pipeline { stages { stage('docker-ssh-agent') { + environment { + DOCKERHUB_ORGANISATION = "${infra.isTrusted() ? 'jenkins' : 'jenkins4eval'}" + } matrix { axes { axis { @@ -35,9 +38,6 @@ pipeline { options { timeout(time: 60, unit: 'MINUTES') } - environment { - DOCKERHUB_ORGANISATION = "${infra.isTrusted() ? 'jenkins' : 'jenkins4eval'}" - } stages { stage('Prepare Docker') { when { @@ -75,18 +75,18 @@ pipeline { when { buildingTag() } + environment { + ON_TAG = 'true' + VERSION = "${env.TAG_NAME}" + } steps { script { // This function is defined in the jenkins-infra/pipeline-library infra.withDockerCredentials { if (isUnix()) { - sh ''' - export ON_TAG=true - export VERSION="${TAG_NAME}" - make publish - ''' + sh 'make publish' } else { - powershell '& ./build.ps1 -VersionTag $env:TAG_NAME publish' + powershell '& ./build.ps1 publish' } } } diff --git a/build.ps1 b/build.ps1 index f796646d..9871ff61 100644 --- a/build.ps1 +++ b/build.ps1 @@ -31,6 +31,10 @@ if(![String]::IsNullOrWhiteSpace($env:DOCKERHUB_ORGANISATION)) { $Organisation = $env:DOCKERHUB_ORGANISATION } +if(![String]::IsNullOrWhiteSpace($env:VERSION)) { + $VersionTag = $env:VERSION +} + if(![String]::IsNullOrWhiteSpace($env:IMAGE_TYPE)) { $ImageType = $env:IMAGE_TYPE }