ItsAnApe
ItsAnApe

Reputation: 422

How to correctly specify bitbucket checkout in Jenkinsfile

I've very new to Jenkins and wanted to make sure that I could automatically trigger a pipeline upon a push to my repository. To that end i followed this tutorial. Everything works fine, but the part I haven't been able to understand is the instructions around 3:40 seconds, we use the Jenkins pipeline syntax generator to create a 'bbs_checkout' step. This should then be pasted into the Jenkinsfile that lives with the SCM. Lets say my Jenkinsfile looked like this:

pipeline{
    agent any
    stages{
        stage('Checkout'){
            steps{
                  echo "about to checkout bitbucket"
                  bbs_checkout <<checkout information generated by the pipeline syntax generator>>
                  echo "done checking out bitbucket
            }
        }
    }
}

When i push to my bitbucket server, and then look at the output log on Jenkins, I see that I actually end up cloning my repository twice. It seems to occur once all on its own (not explicitly declared in the pipeline) and then again when it hits the checkout step. This makes sense because how could Jenkins ever see the Jenkinsfile if it hadn't already cloned the repository. If i remove the bbs_checkout step, i still clone the repo. So what was the point?

Upvotes: 0

Views: 2553

Answers (1)

MaratC
MaratC

Reputation: 6889

If your job type is "Pipeline from SCM", you can check "Lightweight checkout" box. This will only bring the Jenkinsfile in the first checkout.

If, for some other reason, you want the first checkout but not the second one, use

pipeline {
  options {
    skipDefaultCheckout true
  }

You will then need to explicitly request checkout, by using e.g. checkout scm where needed.

Upvotes: 1

Related Questions