20

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?

  • 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 Pareja 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? – Michael Le Barbier Grünewald 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 Pareja 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. – Michael Le Barbier Grünewald Apr 29 '17 at 18:40
23

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'
      }
    }
  }
}
| improve this answer | |
6

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

node {
        skipDefaultCheckout()
        //...
}
| improve this answer | |
  • 1
    Could you add a link to the documentation and explain more about skipDefaultCheckout()? – 030 Oct 6 '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 6 '17 at 12:05
  • 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.

| improve this answer | |
  • Please include a relevant quote from that linked answer ... – Pierre.Vriens Apr 28 '17 at 21:43
  • 1
    Welcome to DevOps! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – Richard Slater Apr 28 '17 at 22:22
  • @RichardSlater I'm not sure about the policy on DevOps, but other sites make an exception for in-network links. – chicks Apr 29 '17 at 0:06
  • 3
    @chicks even StackOverflow links are subject to link rot and by summarising the question it gives a clear indication to other reasons why the answerer believes the question is answered by the link. – Richard Slater Apr 29 '17 at 0:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.