【问题标题】:How to trigger a multiple run in a single pipeline job of jenkins?如何在詹金斯的单个管道作业中触发多次运行?
【发布时间】:2019-02-25 11:11:22
【问题描述】:

我有一个使用以下管道常规脚本运行的管道作业,

pipeline {
     parameters{
    string(name: 'Unique_Number', defaultValue: '', description: 'Enter Unique Number')
        }  
    stages {
            stage('Build') {
            agent { node {  label 'Build'  } }
            steps {
               script {
               sh build.sh
                    }
                }

            stage('Deploy') {
            agent { node {  label 'Deploy'  } }
            steps {
               script {
               sh deploy.sh
                    }
                }

            stage('Test') {
            agent { node {  label 'Test'  } }
            steps {
               script {
               sh test.sh
                    }
                }

           }
         }

我只是使用不同的唯一 ID 号作为输入参数多次触发此作业。因此,我将在不同阶段为这项工作进行多次运行/构建。

有了这个,我需要在这个管道作业中触发多次运行/构建以提升到下一个阶段(即从构建到部署或从部署到测试)作为一个单一构建而不是触发每个运行/构建到下一阶段。有没有可能?

【问题讨论】:

    标签: jenkins-pipeline


    【解决方案1】:

    我也在尝试做同样的事情,但没有找到相关的答案。愿这对某人有所帮助。

    这将读取一个包含 Jenkins 作业名称的文件,并从一个作业中迭代地运行它们。

    请在您的 Jenkins 中相应地更改以下代码。

    pipeline {
       agent any
    
       stages {
          stage('Hello') {
             steps {
                 script{
                git branch: 'Your Branch name', credentialsId: 'Your crendiatails', url: ' Your BitBucket Repo URL '
    
    ##To read file from workspace which will contain the Jenkins Job Name ###
               
         def filePath = readFile "${WORKSPACE}/ Your File Location"                   
    
    ##To read file line by line ###
     
         def lines = filePath.readLines() 
          
    ##To iterate and run Jenkins Jobs one by one ####
    
                        for (line in lines) {                                            
                          build(job: "$line/branchName",
                            parameters:
                            [string(name: 'vertical', value: "${params.vertical}"),
                            string(name: 'environment', value: "${params.environment}"),
                            string(name: 'branch', value: "${params.aerdevops_branch}"),
                            string(name: 'project', value: "${params.host_project}")
                            ]
                        )
                            }  
                                           }
                        
             }
             }
          }
       }

    【讨论】:

      【解决方案2】:

      如果您运行以下内容,则可以从一个管道启动多个作业:

      build job:"One", wait: false
      build job:"Two", wait: false
      

      您的主要工作启动子管道,子管道将并行运行。

      您可以阅读PipeLine Build Step documentation for more information

      另外,您可以阅读parallel run in declarative pipeline

      Here你可以找到很多并行运行的例子

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-06-04
        • 1970-01-01
        • 1970-01-01
        • 2014-10-23
        • 1970-01-01
        • 2014-07-10
        • 1970-01-01
        相关资源
        最近更新 更多