28

I have integrated Jenkins with Bitbucket using the Bitbucket Plugin. As per the plugin's Wiki, a given job will be triggered if the repository is set in the SCM of the job. As you know, if one set SCM in a Jenkins job, this is cloned in pre-build stage.

So far so good. However, the main purpose of the job I'm setting has nothing to do with the repository's content; instead, I just want the job to process the payload sent by Bitbucket. One could say it's not a big deal in terms of storage to clone a repository despite you really don't need it. I don't think so, adding unnecessary steps, consuming time and resources is not a good practice.

So, the question is: Does anyone know how to set an SCM in a Jenkins job but prevent it to clone the repository?

Héctor Valverde
  • 383
  • 1
  • 3
  • 8

3 Answers3

27

Yes, definitely. I do this all the time. You can specify configuration options for your pipeline and one of them is skipDefaultCheckout, which causes pipeline to skip the default "Declarative: Checkout SCM" stage.

The skipDefaultCheckout option is documented in Pipeline Syntax and here's an example Jenkinsfile showing how to use it:

pipeline {
  agent { label 'docker' }
  options {
    skipDefaultCheckout true
  }
  stages {
    stage('commit_stage') {
      steps {
        echo 'sweet stuff here'
      }
    }
  }
}
Richard Slater
  • 11,747
  • 7
  • 43
  • 82
burnettk
  • 486
  • 3
  • 6
8

In case you're not using the Declarative Pipeline, you can avoid checking out from SCM by:

node {
        skipDefaultCheckout()
        //...
}
user3118604
  • 189
  • 1
  • 1
2

I think what you want to achieve is processing a webhook payload in a Jenkins job. Using bitbucket plugin won't be necessary and it is probably strongly designed to clone the repo.

I belive this stackoverflow answer could help you.

Fanch
  • 74
  • 4