Jenkins 流水线:“输入"步骤块执行器 [英] Jenkins Pipeline: "input" step blocks executor
问题描述
经过 管道 和 Jenkinsfile 文档,我对如何创建 Stage -> Production 管道有点困惑.
After going through the pipeline and Jenkinsfile documentation, I am a bit confused on how to create a Stage -> Production pipeline.
一种方法是使用 input
步骤,如
One way is to use the input
step like
node() {
stage 'Build to Stage'
sh '# ...'
input 'Deploy to Production'
stage 'Build to Production'
sh '# ...'
}
这似乎有点笨拙,因为这会一直阻塞执行程序,直到您想要部署到生产环境.有没有其他方法可以从 Jenkins 部署到生产环境.
This seems a bit clunky, as this will block an executor all the time until you want to deploy to production. Is there any alternative way of being able to deploy to production, from Jenkins.
推荐答案
编辑(2016 年 10 月):请查看我的其他答案 使用里程碑和锁定",其中包括最近引入的功能.
EDIT (Oct 2016): Please see my other answer "Use milestone and lock" below, which includes recently introduced features.
作为第一个选项,您可以将 sh
步骤包装到 timeout
步骤.
As first option, you can wrap your sh
step into a timeout
step.
node() {
stage 'Build to Stage' {
sh '# ...'
}
stage 'Promotion' {
timeout(time: 1, unit: 'HOURS') {
input 'Deploy to Production?'
}
}
stage 'Deploy to Production' {
sh '# ...'
}
}
这会在超时后停止构建.
This stops the build after the timeout.
另一种选择是不为 input
步骤分配重量级执行器.您可以使用 node
块之外的 input
步骤来执行此操作,如下所示:
Another option is to not allocate a heavyweight executor for the input
step. You can do this by using the input
step outside of the node
block, like this:
stage 'Build to Stage' {
node {
sh "echo building"
stash 'complete-workspace'
}
}
stage 'Promotion' {
input 'Deploy to Production?'
}
stage 'Deploy to Production' {
node {
unstash 'complete-workspace'
sh "echo deploying"
}
}
这个是 是 可能是更优雅的方式,但仍然可以与 timeout
步骤结合使用.
This is was probably the more elegant way, but can still be combined with the timeout
step.
正如@amuniz 所指出的,您必须存储/取消存储工作区的内容,因为可能会为两个 node
步骤分配不同的节点和工作区目录.
As pointed out by @amuniz, you have to stash/unstash the contents of the workspace, as different nodes respectively workspace directories might be allocated for the two node
steps.
这篇关于Jenkins 流水线:“输入"步骤块执行器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!