【问题标题】:Can I run the jenkins high level stages in parallel?我可以并行运行 jenkins 高级阶段吗?
【发布时间】:2019-04-19 07:04:07
【问题描述】:

我有一些并行测试的 groovy 脚本,但我无法从 jenkins UI 手动重新启动阶段 Installation1/Installation2。有没有其他方法可以让我重新启动特定阶段?

pipeline {
     agent {label ''}
     stages {
             stage('Check workspace') {
             steps {
             }
             }
             stage('Installation') {
             parallel{
                        stage('Installation 1')
                        {
                        agent {label ''}
                        steps {
                            }
                        }
                    }
                        stage('Installation 2')
                        {
                        agent {label ''}
                        steps {
                            }
                        }
                    }
             }
             }
             stage('Test') {
             parallel{
                        stage(' Tests 1'){
                        agent {label ''}
                        steps {
                            }
                        }
                        stage(' Tests 2'){
                        agent {label ''}
                        steps {
                            }
                        }
                        }
                    }
             stage('Report') {
             steps {
             }
             }  
        }
    }

【问题讨论】:

  • 考虑在阶段使用“参数”与条件(“何时”)混合

标签: jenkins jenkins-pipeline jenkins-groovy


【解决方案1】:

您可以在 Jenkinsfile 中将 installation1 和 installation2 阶段定义为函数,并在测试失败时调用它们。这些功能可用于安装阶段以及测试失败时的重新安装。

def installation1() {
   stage('Installation 1')
                        {
                        agent {label ''}
                        steps {
                            }
                        }
}

def installation2() {
   stage('Installation 2')
                        {
                        agent {label ''}
                        steps {
                            }
                        }
}

在并行步骤中,您可以调用如下函数。测试失败时使用 try-catch 调用安装函数。

 stage('Test') {
   try {
     "TEST YOUR INSTALLATION"
   } catch(error) {
     echo "First test failed, let's retry installation if accepted"
     retry(2) {
        input "Retry the installation ?"
        parallel{
           installation1(),
           installation2()
      }
     }
   }
}

此代码未经测试。希望对你有帮助:)

【讨论】:

    猜你喜欢
    • 2016-08-20
    • 2023-01-21
    • 1970-01-01
    • 1970-01-01
    • 2023-01-10
    • 2017-08-07
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多