詹金斯管道:“输入"步骤块执行器 [英] Jenkins Pipeline: "input" step blocks executor
问题描述
经过管道和
After going through the pipeline and Jenkinsfile documentation, I am a bit confused on how to create a Stage -> Production pipeline.
一种方法是像input
步骤
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.
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.
这篇关于詹金斯管道:“输入"步骤块执行器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!