diff --git a/Jenkinsfile b/Jenkinsfile index 4e2fcd4..dcd584c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,6 +2,20 @@ properties([ buildDiscarder(logRotator(numToKeepStr: '20')) ]) +def bunBinDir() { + if (isUnix()) { + return "${env.HOME}/.bun/bin" + } + return "${env.USERPROFILE}/.bun/bin" +} + +def withBun(Closure body) { + def sep = isUnix() ? ':' : ';' + withEnv(["PATH=${bunBinDir()}${sep}${env.PATH}"]) { + body() + } +} + def ensureBunInstalled() { if (isUnix()) { sh ''' @@ -13,14 +27,12 @@ def ensureBunInstalled() { fi bun -v ''' - env.PATH = "${env.HOME}/.bun/bin:${env.PATH}" } else { bat ''' - where bun >nul 2>nul || powershell -c "irm bun.sh/install.ps1 | iex" + where bun >nul 2>nul || %SystemRoot%/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "irm bun.sh/install.ps1 | iex" set PATH=%USERPROFILE%/.bun/bin;%PATH% bun -v ''' - env.PATH = "${env.USERPROFILE}/.bun/bin;${env.PATH}" } } @@ -43,20 +55,22 @@ def buildLinux() { checkout scm } - stage('Setup Bun (Ubuntu)') { - ensureBunInstalled() - } + withBun { + stage('Setup Bun (Ubuntu)') { + ensureBunInstalled() + } - stage('Install Dependencies (Ubuntu)') { - sh 'bun install --frozen-lockfile' - } + stage('Install Dependencies (Ubuntu)') { + sh 'bun install --frozen-lockfile' + } - stage('Write Build Metadata (Ubuntu)') { - writeBuildMetadata() - } + stage('Write Build Metadata (Ubuntu)') { + writeBuildMetadata() + } - stage('Build (Ubuntu)') { - sh "VITE_BUILD_NUMBER=${env.BUILD_NUMBER} NODE_ENV=production bun run build:linux" + stage('Build (Ubuntu)') { + sh "VITE_BUILD_NUMBER=${env.BUILD_NUMBER} NODE_ENV=production bun run build:linux" + } } stage('Archive Artifacts (Ubuntu)') { @@ -75,27 +89,29 @@ def buildOnLabel(label, buildCommand) { checkout scm } - stage("Setup Bun (${label})") { - ensureBunInstalled() - } - - stage("Install Dependencies (${label})") { - if (isUnix()) { - sh 'bun install --frozen-lockfile' - } else { - bat 'bun install --frozen-lockfile' + withBun { + stage("Setup Bun (${label})") { + ensureBunInstalled() } - } - stage("Write Build Metadata (${label})") { - writeBuildMetadata() - } + stage("Install Dependencies (${label})") { + if (isUnix()) { + sh 'bun install --frozen-lockfile' + } else { + bat 'bun install --frozen-lockfile' + } + } - stage("Build (${label})") { - if (isUnix()) { - sh "VITE_BUILD_NUMBER=${env.BUILD_NUMBER} NODE_ENV=production ${buildCommand}" - } else { - bat "set VITE_BUILD_NUMBER=${env.BUILD_NUMBER} && set NODE_ENV=production && ${buildCommand}" + stage("Write Build Metadata (${label})") { + writeBuildMetadata() + } + + stage("Build (${label})") { + if (isUnix()) { + sh "VITE_BUILD_NUMBER=${env.BUILD_NUMBER} NODE_ENV=production ${buildCommand}" + } else { + bat "set VITE_BUILD_NUMBER=${env.BUILD_NUMBER} && set NODE_ENV=production && ${buildCommand}" + } } } @@ -110,14 +126,16 @@ def setBuildNameFromPackageVersion() { node('ubuntu') { stage('Set Build Name') { checkout scm - ensureBunInstalled() - def version = sh( - script: "bun --eval \"console.log(JSON.parse(await Bun.file('package.json').text()).version)\"", - returnStdout: true - ).trim() - def buildName = "v${version}-b${env.BUILD_NUMBER}" - currentBuild.displayName = buildName - echo "Build name set to: ${buildName}" + withBun { + ensureBunInstalled() + def version = sh( + script: "bun --eval \"console.log(JSON.parse(await Bun.file('package.json').text()).version)\"", + returnStdout: true + ).trim() + def buildName = "v${version}-b${env.BUILD_NUMBER}" + currentBuild.displayName = buildName + echo "Build name set to: ${buildName}" + } } } }