sssilver
sssilver

Reputation: 2869

checkout scm in Jenkinsfile

I have the following advanced scripted pipeline in a Jenkinsfile:

stage('Generate') {
    node {
        checkout scm
    }

    parallel windows: {
        node('windows') {
            sh 'cmake . -Bbuild.windows -A x64'
        }
    },
    macos: {
        node('apple') {
            sh '/usr/local/bin/cmake . -DPLATFORM="macos" -Bbuild.macos -GXcode'
        }
    },
    ios: {
        node('apple') {
            sh '/usr/local/bin/cmake . -DPLATFORM="ios" -Bbuild.ios -GXcode'
        }
    }
}

Note the top node that precedes the parallel windows/macos/ios nodes. Does this mean that checkout scm will be invoked on every subsequent building node (windows/apple), before proceeding to the parallel steps? In other words, does the script above guarantee that the repository will be checked out on every node that will be involved at any stage of this build?

Many thanks.

Upvotes: 10

Views: 66579

Answers (1)

StephenKing
StephenKing

Reputation: 37630

The first node step will allocate any build agent and check out the source code. Later, additional nodes will be allocated, where I can promise you that cmake will fail, as it works with an empty directory.

You can use stash and unstash to copy over the files that are needed for the build (and subsequent stages):

stage('Generate') {
    node {
        checkout scm
        stash 'source'
    }

    parallel windows: {
        node('windows') {
            unstash 'source'
            sh 'cmake . -Bbuild.windows -A x64'
        }
    },
    macos: {
        node('apple') {
            unstash 'source'
            sh '/usr/local/bin/cmake . -DPLATFORM="macos" -Bbuild.macos -GXcode'
        }
    },
    ios: {
        node('apple') {
            unstash 'source'
            sh '/usr/local/bin/cmake . -DPLATFORM="ios" -Bbuild.ios -GXcode'
        }
    }
}

Upvotes: 20

Related Questions