1
votes

I have an issue with Jenkins Pipeline. I have two application that i want to checkout and test in parallel :

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

I don't understand exactly how it works, because it says :

[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

But in the Test stage workspace switch :

[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

So my test's stage is not relevant.

What can i do in order to fix this problem?

1

1 Answers

3
votes

For each parallel step, during the execution, the own Jenkins duplicate the workspace like you have seen.

You can't have a parallel step for checkout the code and after, other parallel step for testing. You can try to have under the same step the checkout and the test, without having two parallels. Only one parallel:

  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"
                   }
               }
            }

But is not a good practice to mix different repositories of code under the same pipeline.