Ram*_*Ram 2 jenkins cloudbees checkpointing jenkins-pipeline
我正在查看Cloudbees 文档,该文档说:
正确的方法是始终将检查点步骤保持在任何节点块之外,不与代理或工作区相关联
给出的示例示例适用于脚本化管道。我试图在声明式管道中实现这一点,但不断出错。我可以让它工作的唯一方法是:
stage ('Promotion Checkpoint') {
steps {
checkpoint 'Ready for Manual intervention'
timeout(time: 60, unit: 'SECONDS') {
input message: 'Do you want to proceed?'
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的理解是声明式管道中的一个阶段类似于脚本管道中的节点。我不能在阶段或步骤之外进行检查点工作,这似乎是我对 Cloudbees 建议的解释。有人可以帮助在检查站之外正确使用吗?
您正面临声明性管道的问题,这使得应该在代理和工作区之外运行的事情有点混乱。
“正常”声明式管道在顶部定义了一个代理
pipeline {
agent any
stages {
stage("Build") {
echo 'Build'
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是现在所有阶段标签都将使用相同的代理和工作区。这使得编写“标准”管道变得更容易,但无法使用不使用任何代理的命令。因此,在使用时使用checkpoint或编写不阻塞执行程序的管道input变得不可能。
因此,对于声明管道的建议正确的方法是使用agent none在顶层的管道,并指定agent any或agent none在每个stage。
CloudBees 文档中有两个示例。您还可以input在 Jenkins 文档中找到此类解决方法。
因此,使用代理开关的一种解决方案如下所示:
pipeline {
agent none
stages {
stage("Build") {
agent any
steps {
echo "Building"
}
}
stage("Checkpoint") {
agent none //running outside of any node or workspace
steps {
checkpoint 'Completed Build'
}
}
stage("Deploy") {
agent any
steps {
sh 'Deploying'
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
还有一个node在声明性管道中使用块。
pipeline {
agent none
stages{
stage("Build"){
// no agent defined will be solved with node
steps{
node('') { // this is equivalent to 'agent any'
echo "Building"
}
checkpoint "Build Done"
}
}
stage("Deploy") {
agent any
steps {
echo 'Deploy'
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5355 次 |
| 最近记录: |