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
  • 2
    It sounds like you're trying to use Jenkins as a micro service which is kind of out of the scope of Jenkins :). Do post back if you get this working though because it is interesting. – Travis Thompson Mar 29 '17 at 16:33
  • I'm not using Jenkins as a micro service. Why do you say that? In reality, all of this is a work around: I'm using a Pipeline Job which is common to many repositories. Jenkinsfile is in a different repository. Thus, I can't trigger the pipeline directly with the Bitbucket Plugin because it just don't trigger it, so I decided to create a "proxy job" per repo, and send the information to the pipeline as a downstream job. In such "proxy job" I don't need to clone the repo, but it needs to be in SCM. – Héctor Valverde Mar 29 '17 at 16:39
  • It is very hard to understand and you write more about what is impossible than about what you actually want to achieve, Maybe you can add more details about what you are actually want to achieve and how your proxy jobs fit in there? – Michaël Le Barbier Apr 24 '17 at 19:45
  • I guess you're talking about my comment above. It's just an answer to the first comment. Please refer to the main question, there is nothing else to add. What I want you achieve is very clear: "Prevent Jenkins to clone a repository during the build". – Héctor Valverde Apr 24 '17 at 23:08
  • 1
    @HéctorValverdePareja Sure, but your wording seems to hesitate between A/giving enough details so that everybody can check if you're in a XY-problem situation and B/just to focus on the precise thing you want to achieve. I think (opinion) you could remove this hesitation by describing carefully enough your original problem and the solution you are trying to implement. But now that someone wrote an answer, this might be not so important anymore. – Michaël Le Barbier Apr 29 '17 at 18:40
  • Hi @MichaëlLeBarbier - late recovery of this threat, sorry. I see my wording in the comment above was not clear (you were right on that), and I could give more context to the problem (to the expenses of simplicity). But despite I implicitly told you to ignore the anwer to Travis comment, your second comment still circled around it. I think you were wrong to criticise the narrative of my comment responding to the "side topic" of microservices, and you failed to recognise that the original post was clear enough. – Héctor Valverde Aug 28 '22 at 00:00
  • If people who try to help you do not understand the problem you are describing and the problem you are trying to solve, it might be a good idea to rephrase, add more details etc. No biggie :-) – Michaël Le Barbier Aug 28 '22 at 08:02

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,612
  • 6
  • 41
  • 81
burnettk
  • 466
  • 3
  • 4
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
    Could you add a link to the documentation and explain more about skipDefaultCheckout()? – 030 Oct 06 '17 at 11:36
  • I don't see any added value compared to existing answer, that's just a 'try this' with no explanation and not a good answer. – Tensibai Oct 06 '17 at 12:05
  • 1
    This answer is fine as a supplement to the accepted answer - not everyone will be using the declarative Pipeline plugin, so this works for those using the procedural one. – RichVel Nov 23 '17 at 13:53
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