我可以并行运行jenkins高级阶段吗?

问题描述 投票:0回答:1

我有一个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个回答
0
投票

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

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()
      }
     }
   }
}

此代码未经过测试。希望能帮助到你 :)

© www.soinside.com 2019 - 2024. All rights reserved.