I've moved a few old Jenkins jobs to new ones using the pipeline feature in order to be able to integrate the Jenkins configuration within the git repositories. It's working fine but I'm asking myself if there is a way to reduce the number of checkout that happens while building.
Setup
- I have a Jenkins multibranch job which is related to my git repository
I have a Jenkinsfile in my git repository
#!groovy node { stage 'Checkout' checkout scm // build project stage 'Build' ... }
Problem
When I push to my remote branche BRANCH_1, the multibranch jenkins job is triggered and my understanding is that the following steps happen:
- the multibranch job makes a
git fetchfor the branch indexing and triggers the job corresponding to my remote branch: BRANCH_1_job - BRANCH_1_job makes a
git checkoutto retrieve the Jenkinsfile of the triggered branch - the Jenkinsfile is executed and makes a
checkout scmitself. If I don't do it, I can not build my project because no source are available.
So for building my branch, I end up with one git fetch and two git checkout.
Questions
- Do I understand the process correctly? Or did I miss something?
- Is there a way to reduce the number of
git checkout? When I check the official examples, they all make a checkout scm as first step. I would personally think that I don't have to do it because the jenkins job already had to make a checkout to retrieve the Jenkinsfile (so my sources have to be here somehow). - Don't you think these multiple checkouts can cause bad performance as soon as the git repo contains a big number of refs?
Thanks you all
Jenkinsfilein Jenkins which performs a single checkout and then loads your actual build script from the checked out repository viaload 'ci/build-script-in-your-repo.gy'. Unfortunately, you would loose the separate jobs for each branch in that case. - Carsten