并行示例Jenkinsfile声明性管道失败

时间:2018-04-26 05:23:52

标签: jenkins jenkins-pipeline

使用Jenkinsfile Parallel Example - 挂起等待安排任务。我假设这个例子应该有效。以示例为例,由于

,跳过了并行阶段
when branch master

所以我删除它。不幸的是,这会导致进程挂起。我还在代理标签上添加了节点......没有帮助

agent { node { label "for-branch-a" } }

有人可以告诉我如何让这个工作吗?

pipeline {
  agent any
  stages {
    stage('Non-Parallel Stage') {
      steps {
        echo 'This stage will be executed first.'
      }
    }
    stage('Parallel Stage') {
      when {
        branch 'master'
      }
      failFast true
      parallel {
        stage('Branch A') {
          agent {
            label "for-branch-a"
          }
          steps {
            echo "On Branch A"
          }
        }
        stage('Branch B') {
          agent {
            label "for-branch-b"
          }
          steps {
            echo "On Branch B"
          }
        }
      }
    }
  }
}

挂在A和B分支上

> This stage will be executed first.
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Parallel Stage)
[Pipeline] parallel
[Pipeline] [Branch A] { (Branch: Branch A)
[Pipeline] [Branch B] { (Branch: Branch B)
[Pipeline] [Branch A] stage
[Pipeline] [Branch A] { (Branch A)
[Pipeline] [Branch B] stage
[Pipeline] [Branch B] { (Branch B)
[Pipeline] [Branch A] node
[Pipeline] [Branch B] node
[Branch A] Still waiting to schedule task
[Branch A] There are no nodes with the label ‘for-branch-a’
[Branch B] Still waiting to schedule task
[Branch B] There are no nodes with the label ‘for-branch-b’

2 个答案:

答案 0 :(得分:1)

[Branch A] There are no nodes with the label ‘for-branch-a’ [Branch B] There are no nodes with the label ‘for-branch-b’ 这意味着你没有带有这些名字的奴隶,根据詹金斯(https://wiki.jenkins.io/display/JENKINS/Distributed+builds)的指南设置它们然后一切都会起作用

答案 1 :(得分:0)

如@BigGinDaHouse所述,我没有创建代理商。我已更新并行示例以使用Docker代理: 注意:此版本仅在我们从docker代理定义中删除“label”属性时才有效。

pipeline {
  agent any
  stages {
    stage('Non-Parallel Stage') {
      steps {
        echo 'This stage will be executed first.'
      }
    }
    stage('Parallel Stage') {
      failFast true
      parallel {
        stage('Branch A') {
            agent { 
              docker{ 
                image 'alpine:latest'  
                label 'for-branch-a'   # remove this
              }
            }
            steps {
              echo "On Branch A"
            }
        }
        stage('Branch B') {
          agent { 
            docker { 
              image 'alpine:latest' 
              label 'for-branch-b'     # remove this
            }
          }
          steps {
            echo "On Branch B"
          }
        }
      }
    }
  }
}