Jenkins 声明式管道无限期地等待执行者

Jenkins declarative pipeline waits for executor indefinitely

我不是 Jenkins 专家,所以如果这是一个绝对的菜鸟问题,请原谅。

我目前正在调查与我们的 Jenkins 管道相关的问题。尝试从 AWS EC2 提供执行器时,连接超时。我希望这项工作在重试几次后中止。相反,它一直在尝试连接。连接一直超时。无限循环!

管道中定义了超时。由于没有执行者,永远不会读取超时。

pipeline {

   agent {
       label 'docker'
   }

    options {
         timeout(time: 45, unit: 'MINUTES')
         timestamps()
         skipDefaultCheckout()
         disableConcurrentBuilds()
         buildDiscarder(logRotator(numToKeepStr:'5'))
    }

    stages {
        // And so on...

我们的Jenkins上安装了'Build Timeout'插件,但是对于这个项目好像没有激活,所以我没有看到中止项目的设置。

已安装的插件

请注意,该管道过去一直有效。

[编辑]

以下日志几天没有更改。

Started by user a.user
 > git rev-parse --is-inside-work-tree # timeout=10
Setting origin to http://sources:8080/scm/git/backend
 > git config remote.origin.url http://sources:8080/scm/git/backend # timeout=10
Fetching origin...
Fetching upstream changes from origin
 > git --version # timeout=10
 > git config --get remote.origin.url # timeout=10
using GIT_ASKPASS to set credentials provides read-only access to the project git repositories
 > git fetch --tags --progress origin +refs/heads/*:refs/remotes/origin/* # timeout=10
Seen branch in repository origin/branch1
Seen branch in repository origin/branch2
Seen branch in repository origin/branch3
Seen branch in repository origin/branch4
Seen branch in repository origin/branch5
Seen branch in repository origin/branch6
Seen branch in repository origin/branch7
Seen branch in repository origin/branch8
Seen branch in repository origin/branch9
Seen branch in repository origin/branch10
Seen branch in repository origin/branch11
Seen branch in repository origin/branch12
Seen branch in repository origin/branch13
Seen 13 remote branches
Obtained ci/jobs/Backend-Build-Multibranch/Jenkinsfile from d6d39ddab89bb77502c83f99c7f08f0b6eb03e77
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Still waiting to schedule task
Waiting for next available executor

您看到的等待执行者的确切消息是什么? 可能是当作业被触发时没有从属 运行 标签 'docker' and/or 新的从属也没有被触发(可能是由于 AMI/ec2 的静态从属计数实例上限或没有动态从站旋转)

要为代理连接设置超时,您可以为一个阶段而不是整个管道定义 agent { label 'docker' }。在此阶段中,您可以为您之前在顶层定义的阶段创建嵌套阶段,因此当 "docker" 节点可用时,它们将全部 运行。

pipeline {
    agent{ label 'master' }

    options {
        timeout(time: 45, unit: 'MINUTES')
    }    

    stages {
        stage('Connect Node') {
            agent { label 'docker' }

            stages {
                stage('Build') {
                    steps{
                        echo 'Hello'
                    }
                }
                // And so on...
            }
        }
    }
}

这里是对https://whosebug.com/users/7571258/zett42的回答的修改:

pipeline {
   // 'agent none' prevents Jenkins from starting the node. 'agent' must be
   // defined in subsequent stages.
   agent none

    // Options are read and applied globally.
    options {
         timeout(time: 45, unit: 'MINUTES')
    }

    stages {
        // Node connection stage will time out as declared in the options block
        stage('Connect Node') {
            agent {
                label 'docker'
            }

            stages {
                // And so on...
            }
        }
    }
}