From 25e35afe094067ef1043aecd99105843ecf34fee Mon Sep 17 00:00:00 2001 From: kdletters Date: Thu, 23 Apr 2026 04:34:21 +0800 Subject: [PATCH] chore(jenkins): move deploy target under jenkins home --- .../JENKINS_RUST_BUILD_DEPLOY_PIPELINES_2026-04-23.md | 5 +++-- jenkins/Jenkinsfile.build-and-deploy | 2 +- jenkins/Jenkinsfile.deploy | 2 +- scripts/jenkins-deploy-release.sh | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/technical/JENKINS_RUST_BUILD_DEPLOY_PIPELINES_2026-04-23.md b/docs/technical/JENKINS_RUST_BUILD_DEPLOY_PIPELINES_2026-04-23.md index ce171cc3..10404b3c 100644 --- a/docs/technical/JENKINS_RUST_BUILD_DEPLOY_PIPELINES_2026-04-23.md +++ b/docs/technical/JENKINS_RUST_BUILD_DEPLOY_PIPELINES_2026-04-23.md @@ -7,7 +7,7 @@ 本方案为当前仓库补齐 3 条 Jenkins 流水线: 1. `构建`:只负责在仓库根目录执行 `npm run deploy:rust:remote -- --skip-upload`,生成发布包。 -2. `部署`:只负责把指定发布版本部署到 `/home/ubuntu/Genarrative-deploy/`,禁止人工直接点击执行。 +2. `部署`:只负责把指定发布版本部署到 `/var/lib/jenkins/deploy/Genarrative/`,禁止人工直接点击执行。 3. `构建并部署`:先构建,再把构建出的版本号传给 `部署` 流水线并等待部署完成。 本次只补 Jenkins 编排与本地部署脚本,不改现有 Rust 发布包构建逻辑,不恢复旧 `server-node` 部署链。 @@ -81,7 +81,7 @@ jenkins/Jenkinsfile.deploy ```bash scripts/jenkins-deploy-release.sh \ --source-dir /build/ \ - --deploy-dir /home/ubuntu/Genarrative-deploy + --deploy-dir /var/lib/jenkins/deploy/Genarrative ``` 脚本语义: @@ -123,6 +123,7 @@ jenkins/Jenkinsfile.build-and-deploy 4. `RUN_NPM_CI`:是否在构建前执行 `npm ci`。 如果当前 Jenkins 没有额外配置独立 Agent,而是直接在控制器自身执行任务,`AGENT_LABEL` 应填写 `built-in`。 +如果 Jenkins 进程以默认 `jenkins` 用户运行,部署目录建议直接放在 `/var/lib/jenkins/deploy/Genarrative` 这类 Jenkins 自有目录下,避免再依赖 `/home/ubuntu/*` 的额外写权限。 如果目标 Ubuntu 的 Jenkins `sh` 默认实际落到 `/bin/sh -> dash`,而流水线脚本又使用了 `set -euo pipefail`,则必须显式通过 `bash -lc` 执行命令,不能直接依赖 Jenkins 默认 `sh` 解释器。 其中仅 `部署` 流水线还需要: diff --git a/jenkins/Jenkinsfile.build-and-deploy b/jenkins/Jenkinsfile.build-and-deploy index 47c256b7..b63cde20 100644 --- a/jenkins/Jenkinsfile.build-and-deploy +++ b/jenkins/Jenkinsfile.build-and-deploy @@ -12,7 +12,7 @@ pipeline { string(name: 'BUILD_VERSION', defaultValue: '', description: '发布版本号,留空则使用 Jenkins BUILD_NUMBER') booleanParam(name: 'RUN_NPM_CI', defaultValue: false, description: '构建前是否执行 npm ci') string(name: 'DEPLOY_JOB_NAME', defaultValue: 'Genarrative-Deploy', description: '部署流水线作业名') - string(name: 'DEPLOY_DIRECTORY', defaultValue: '/home/ubuntu/Genarrative-deploy', description: '固定部署目录') + string(name: 'DEPLOY_DIRECTORY', defaultValue: '/var/lib/jenkins/deploy/Genarrative', description: '固定部署目录') } stages { diff --git a/jenkins/Jenkinsfile.deploy b/jenkins/Jenkinsfile.deploy index 15201604..e963c5cd 100644 --- a/jenkins/Jenkinsfile.deploy +++ b/jenkins/Jenkinsfile.deploy @@ -10,7 +10,7 @@ pipeline { string(name: 'SOURCE_NODE_NAME', defaultValue: '', description: '上游构建节点名') string(name: 'SOURCE_WORKSPACE_ROOT', defaultValue: '', description: '上游源码根目录') string(name: 'BUILD_VERSION', defaultValue: '', description: '待部署版本号') - string(name: 'DEPLOY_DIRECTORY', defaultValue: '/home/ubuntu/Genarrative-deploy', description: '固定部署目录') + string(name: 'DEPLOY_DIRECTORY', defaultValue: '/var/lib/jenkins/deploy/Genarrative', description: '固定部署目录') string(name: 'EXPECTED_UPSTREAM_JOB', defaultValue: '', description: '允许触发本作业的上游作业名') } diff --git a/scripts/jenkins-deploy-release.sh b/scripts/jenkins-deploy-release.sh index 239ace91..142e1d69 100644 --- a/scripts/jenkins-deploy-release.sh +++ b/scripts/jenkins-deploy-release.sh @@ -5,7 +5,7 @@ set -euo pipefail usage() { cat <<'EOF' 用法: - ./scripts/jenkins-deploy-release.sh --source-dir /path/to/build/123 --deploy-dir /home/ubuntu/Genarrative-deploy + ./scripts/jenkins-deploy-release.sh --source-dir /path/to/build/123 --deploy-dir /var/lib/jenkins/deploy/Genarrative 说明: 1. 如果部署目录已有旧版本且存在 stop.sh,则先执行旧版本 stop.sh。 @@ -15,7 +15,7 @@ usage() { 参数: --source-dir 必填,待部署的发布目录,例如 build/123 - --deploy-dir 必填,固定部署目录,例如 /home/ubuntu/Genarrative-deploy + --deploy-dir 必填,固定部署目录,例如 /var/lib/jenkins/deploy/Genarrative EOF }