Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 916
sssilver Avatar asked Oct 04 '18 01:10

sssilver


People also ask

What is checkout SCM in Jenkinsfile?

The checkout step will checkout code from source control; scm is a special variable which instructs the checkout step to clone the specific revision which triggered this Pipeline run.

What is SCM in Jenkins pipeline?

In Jenkins, SCM stands for "Source Code Management". This option instructs Jenkins to obtain your Pipeline from Source Control Management (SCM), which will be your locally cloned Git repository.

What is SCM checkout retry count in Jenkins?

In a pipeline scm checkout, when using non-lightweight checkout, and the global setting "SCM checkout retry count" is a non-zero value, if a build is performing the initial scm clone and the build is cancelled, the retry will relaunch the scm step as per the retry count.


1 Answers

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'
        }
    }
}
like image 102
StephenKing Avatar answered Sep 17 '22 13:09

StephenKing