【问题标题】:Checkpoint in Declarative Jenkins Pipeline声明式 Jenkins 流水线中的检查点
【发布时间】:2018-08-09 03:31:43
【问题描述】:

我正在查看Cloudbees documentation,上面写着:

正确的方法是始终将检查点步骤保持在任何节点块之外,不与代理或工作区相关联

给出的示例是针对脚本化管道的。我试图在声明式管道中实现这一点,但不断出错。我能让它发挥作用的唯一方法是:

stage ('Promotion Checkpoint') {
    steps {
        checkpoint 'Ready for Manual intervention'
        timeout(time: 60, unit: 'SECONDS') {
            input message: 'Do you want to proceed?'
        }
    }
}

我的理解是声明式管道中的一个阶段类似于脚本管道中的节点。我无法在阶段或步骤之外使检查点工作,这似乎是我对 Cloudbees 建议的解释。有人可以帮助在检查点之外正确使用吗?

【问题讨论】:

  • 以上结果:在节点 {} 内使用检查点不受支持且不可靠

标签: jenkins jenkins-pipeline cloudbees checkpointing


【解决方案1】:

您正面临一个声明性管道问题,这使得应该在代理和工作区之外运行的东西有点混乱。

“正常”声明性管道在顶部定义了一个代理

pipeline {
  agent any
  stages {
    stage("Build") {
      echo 'Build' 
    }
  }
}

但现在所有阶段标签都将使用相同的代理和工作区。这使得编写“标准”管道更容易,但不可能有一个不使用任何代理的命令。因此,使用checkpoint 或在使用input 时编写不阻塞执行程序的管道变得不可能。

因此,建议的声明性管道正确方法是在顶级管道中使用agent none,并在每个stage 中指定agent anyagent none

CloudBees documentation 中有两个示例。您还可以在 Jenkins 文档中找到 input 的此类解决方法。

所以使用代理开关的一种解决方案如下所示:

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'
      }
    }
  }
} 

还有一个在声明性管道中使用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'
      }
    }
  }
}

【讨论】:

  • 谢谢你的解释和链接真的很有帮助。我认为无法全局设置代理并在一个阶段将其覆盖为无是一个错误,但这是另一天的话题
猜你喜欢
  • 2020-04-09
  • 1970-01-01
  • 1970-01-01
  • 2018-10-31
  • 1970-01-01
  • 2021-09-29
  • 1970-01-01
  • 2022-09-26
  • 1970-01-01
相关资源
最近更新 更多