Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
2 views
in DevOps and Agile by (29.3k points)

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?

1 Answer

0 votes
by (50.2k points)

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'

        }

    }

}

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...