fix(jenkins): run pipeline shell steps with bash

This commit is contained in:
2026-04-23 02:52:49 +08:00
parent d0709865bb
commit 000d74d05f
4 changed files with 22 additions and 15 deletions

View File

@@ -121,6 +121,7 @@ jenkins/Jenkinsfile.build-and-deploy
4. `RUN_NPM_CI`:是否在构建前执行 `npm ci`
如果当前 Jenkins 没有额外配置独立 Agent而是直接在控制器自身执行任务`AGENT_LABEL` 应填写 `built-in`
如果目标 Ubuntu 的 Jenkins `sh` 默认实际落到 `/bin/sh -> dash`,而流水线脚本又使用了 `set -euo pipefail`,则必须显式通过 `bash -lc` 执行命令,不能直接依赖 Jenkins 默认 `sh` 解释器。
其中仅 `部署` 流水线还需要:

View File

@@ -33,14 +33,16 @@ pipeline {
script {
// 是否重装依赖交给流水线参数决定,避免每次构建都重复执行 npm ci。
if (params.RUN_NPM_CI) {
sh 'npm ci'
sh 'bash -lc "npm ci"'
}
}
sh """
set -euo pipefail
npm run deploy:rust:remote -- --skip-upload --name "${env.EFFECTIVE_BUILD_VERSION}"
test -d "build/${env.EFFECTIVE_BUILD_VERSION}"
bash -lc '
set -euo pipefail
npm run deploy:rust:remote -- --skip-upload --name "${env.EFFECTIVE_BUILD_VERSION}"
test -d "build/${env.EFFECTIVE_BUILD_VERSION}"
'
"""
archiveArtifacts artifacts: "build/${env.EFFECTIVE_BUILD_VERSION}/**", fingerprint: true

View File

@@ -37,14 +37,16 @@ pipeline {
script {
// 是否重装依赖交给流水线参数决定,避免每次构建都重复执行 npm ci。
if (params.RUN_NPM_CI) {
sh 'npm ci'
sh 'bash -lc "npm ci"'
}
}
sh """
set -euo pipefail
npm run deploy:rust:remote -- --skip-upload --name "${env.EFFECTIVE_BUILD_VERSION}"
test -d "build/${env.EFFECTIVE_BUILD_VERSION}"
bash -lc '
set -euo pipefail
npm run deploy:rust:remote -- --skip-upload --name "${env.EFFECTIVE_BUILD_VERSION}"
test -d "build/${env.EFFECTIVE_BUILD_VERSION}"
'
"""
archiveArtifacts artifacts: "build/${env.EFFECTIVE_BUILD_VERSION}/**", fingerprint: true

View File

@@ -64,13 +64,15 @@ pipeline {
steps {
dir("${params.SOURCE_WORKSPACE_ROOT}") {
sh """
set -euo pipefail
test -d "build/${params.BUILD_VERSION}"
chmod +x scripts/jenkins-deploy-release.sh
# 只部署上游已构建好的版本目录,避免部署阶段再次构建产生漂移。
./scripts/jenkins-deploy-release.sh \
--source-dir "build/${params.BUILD_VERSION}" \
--deploy-dir "${params.DEPLOY_DIRECTORY}"
bash -lc '
set -euo pipefail
test -d "build/${params.BUILD_VERSION}"
chmod +x scripts/jenkins-deploy-release.sh
# 只部署上游已构建好的版本目录,避免部署阶段再次构建产生漂移。
./scripts/jenkins-deploy-release.sh \
--source-dir "build/${params.BUILD_VERSION}" \
--deploy-dir "${params.DEPLOY_DIRECTORY}"
'
"""
}
}