Nathan Osman
Nathan Osman

Reputation: 73195

How to ensure that parallel stages use a copy of a workspace from a previous stage?

I am writing a pipeline for a cross-platform application. The goal is to have a single stage for checking out the source code from SCM and then having a number of slaves build the application for each platform from that checkout.

Here is a rough overview of what I have:

pipeline {
    agent none
    stages {
        stage('Checkout') {
            agent any
            steps {
                checkout([extensions: [[$class: 'CleanBeforeCheckout']], ...]]])
            }
        }
        stage('Build') {
            parallel {
                stage('win') {
                    agent { label 'win' }
                    steps { ... }
                }
                stage('mac') {
                    agent { label 'mac' }
                    steps { ... }
                }
            }
        }
    }
}

The problem is that the parallel stages are not using the clean checkout from the first stage. They are simply reusing the workspace from the previous build.

How would I go about fixing this?

Upvotes: 2

Views: 1535

Answers (1)

Sam
Sam

Reputation: 2882

Stash the workspace in the checkout stage and then unstash in each subsequent stage.

https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#code-unstash-code-restore-files-previously-stashed

Upvotes: 1

Related Questions