Jenkins Pipeline

时间:2017-12-12 09:47:26

标签: jenkins jenkins-pipeline

Jenkins Pipeline存在问题。我有两个应用程序,我想要检查并并行测试:

pipeline {
    agent none
    stages {
        stage('Build') {
            parallel {
               stage('First app') {
                   agent any
                   steps {
                        echo "checkout first app"
                    }
               }
               stage('Second app') {
                   agent any
                   steps {
                        echo "checkout second app"
                   }
               }
            }
         }
         stage('Test') {
             parallel {
                stage('First app') {
                    agent any
                    steps {
                        echo 'test First app'
                    }
                    post {
                        always {
                            junit 'build/*.xml'
                        }
                    }
                }
                stage('Second app') {
                    agent any
                    steps {
                        echo "test second app"
                    }
                    post {
                        failure {
                             echo "failure"
                        }
                    }
                }
            }
        }
        stage('Deploy') {
            echo "Deploy all
        }
    }
}

我不明白它究竟是如何运作的,因为它说:

[First app] Running on maître in /var/lib/jenkins/workspace/My Project
[Second app] Running on maître in /var/lib/jenkins/workspace/My Project@2

但是在Test阶段工作区切换:

[Second app] Running on maître in /var/lib/jenkins/workspace/My Project
[First app] Running on maître in /var/lib/jenkins/workspace/My Project@2

所以我的测试阶段无关紧要。

我该怎么做才能解决这个问题?

1 个答案:

答案 0 :(得分:3)

对于每个并行步骤,在执行期间,自己的Jenkins会像您看到的那样复制工作区。

您无法检查代码以及之后的其他并行步骤进行测试。您可以尝试在结帐和测试的同一步骤,没有两个相似之处。只有一个并行:

  agent none
    stages {
        stage('Build&Test') {
            parallel {
               stage('First app') {
                   agent any
                   steps {
                        echo "checkout first app"
                        echo "test first app"
                    }
               }
               stage('Second app') {
                   agent any
                   steps {
                        echo "checkout second app"
                        echo "test second app"
                   }
               }
            }

但在同一个管道下混合使用不同的代码存储库并不是一个好习惯。