Enhance Bun integration in Jenkinsfile
Some checks failed
farmcontrol/farmcontrol-server/pipeline/head There was a failure building this commit

- Introduced helper functions to manage Bun installation paths for both Unix and Windows environments.
- Wrapped Bun installation and dependency setup stages in a new `withBun` closure for improved readability and organization.
- Ensured consistent handling of Bun installation across different stages of the CI pipeline.
This commit is contained in:
Tom Butcher 2026-07-28 22:14:36 +01:00
parent 0b1530a405
commit de895fed7d

24
Jenkinsfile vendored
View File

@ -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,6 +55,7 @@ def buildLinux() {
checkout scm
}
withBun {
stage('Setup Bun (Ubuntu)') {
ensureBunInstalled()
}
@ -58,6 +71,7 @@ def buildLinux() {
stage('Build (Ubuntu)') {
sh "VITE_BUILD_NUMBER=${env.BUILD_NUMBER} NODE_ENV=production bun run build:linux"
}
}
stage('Archive Artifacts (Ubuntu)') {
archiveArtifacts artifacts: 'app_dist/**/*.deb, app_dist/**/*.rpm', fingerprint: true
@ -75,6 +89,7 @@ def buildOnLabel(label, buildCommand) {
checkout scm
}
withBun {
stage("Setup Bun (${label})") {
ensureBunInstalled()
}
@ -98,6 +113,7 @@ def buildOnLabel(label, buildCommand) {
bat "set VITE_BUILD_NUMBER=${env.BUILD_NUMBER} && set NODE_ENV=production && ${buildCommand}"
}
}
}
stage("Archive Artifacts (${label})") {
archiveArtifacts artifacts: 'app_dist/**/farmcontrol-server-*', fingerprint: true
@ -110,6 +126,7 @@ def setBuildNameFromPackageVersion() {
node('ubuntu') {
stage('Set Build Name') {
checkout scm
withBun {
ensureBunInstalled()
def version = sh(
script: "bun --eval \"console.log(JSON.parse(await Bun.file('package.json').text()).version)\"",
@ -120,6 +137,7 @@ def setBuildNameFromPackageVersion() {
echo "Build name set to: ${buildName}"
}
}
}
}
try {