Scripted Pipeline 中如何正确设置并行构建的 stage 名称?

公孙宇阳 阅读 20

我在 Jenkins 的 Scripted Pipeline 里用 parallel 做并行任务,但每个分支的 stage 名字都显示成 “Branch A”、”Branch B” 这种默认名,想自定义成更有意义的名字,比如 “Build Frontend” 和 “Run Tests”,但改了之后 pipeline 就报错说 stage 名称无效,是不是写法有问题?

我试过这样写:

parallel(
  "Build Frontend": {
    stage("Build Frontend") {
      sh 'npm run build'
    }
  },
  "Run Tests": {
    stage("Run Tests") {
      sh 'npm test'
    }
  }
)
我来解答 赞 7 收藏
二维码
手机扫码查看
1 条解答
a'ゞ雨路
问题在于你在 parallel 里嵌套了 stage,Jenkins Pipeline 不支持这种写法。直接在 parallel 里定义 stage 即可。代码如下:
pre class="pure-highlightjs line-numbers">parallel(
"Build Frontend": {
sh 'npm run build'
},
"Run Tests": {
sh 'npm test'
}
)
点赞
2026-03-22 23:00