jenkins - 在声明性管道中并行在多个代理上运行相同的 Jenkins 作业

标签 jenkins groovy jenkins-pipeline

这是我所拥有的:

#!/usr/bin/env groovy

pipeline {
    agent none
    stages {
        stage('Checkout SCM') {
            agent { label 'win' && 'apple' && 'rhel' }
            steps {
                echo "Cloning Repository"
                checkout([$class: 'GitSCM',
                    branches: [[name: "*/develop"]],
                    doGenerateSubmoduleConfigurations: false,
                    extensions: [[$class: 'WipeWorkspace']],
                    submoduleCfg: [],
                    userRemoteConfigs: [[credentialsId: 'UNAME', url: 'URL']],
                    browser: [$class: 'BitbucketWeb', repoUrl: 'URL'],
                ])}}

        stage('Building Win64, Linux764, MacOS') {
            agent { label 'win&&rhel&&apple' }
            steps {
                   script {
                        echo '************************'
                        echo '*****BUILDING JOBS******'
                        echo '************************'
                        sh 'python build.py'
                        sh 'cd ion-js && npm run prepublishOnly'
                      }}}
    }
} 

但是我得到了 There are no nodes with the label ‘win && rhel && apple’错误。有没有人碰巧知道如何运行声明性 jenkins 管道,其中一个阶段在多个代理标签上并行运行?

我想同时将同一个 git repo checkout 到 3 个不同的节点。我试过 agent { label 'win' && 'apple' && 'rhel' }agent { label 'win&&apple&&rhel' }但它只是说它找不到那个标签。

Here they say you can use ||并使用 &&应该可以,但我不确定我错过了什么。我可以编写 3 个不同的结帐阶段,但我认为有更好的方法

最佳答案

我尝试过同样的事情但没有成功。我知道的唯一解决方案是使用 parallel为每个代理/节点/标签多次阻止和定义阶段。

stage('Building Win64, Linux764, MacOS') {
  parallel {
    stage('Win64') {
      agent {
        label 'win-10-x64'
      }
      steps {
      ...
      }
    }
    stage('Linux64') {
      agent {
        label 'linux-x64'
      }
      steps {
      ...
      }
    }
    stage('MacOS') {
      agent {
        label 'macos'
      }
      steps {
      ...
      }
    }
  }
}

关于jenkins - 在声明性管道中并行在多个代理上运行相同的 Jenkins 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48930433/

相关文章:

jenkins - 多配置 Jenkins 作业订单

windows - 如何在 Teamcity Windows 代理上运行 shell 脚本?

docker - Jenkinsfile 无法使用多个参数运行 docker

jenkins - 在 JenkinsFile 中以 root 身份运行命令

Jenkins git 凭证在阶段中起作用,而不是在下一个阶段中起作用

jenkins - 将管道的一部分作为单独的作业运行

java - 我必须使用 jexcel 使用 java 中的列值对 xls 工作表行进行排序

jenkins - Jenkins 管道脚本中的 Try-catch block

Groovy 替换文件内容的占位符,类似于多行字符串

node.js - jenkins 管道的 docker 容器内的 sudo 权限