Skip to main content

How to Customize Checkout for Pipeline Multibranch?

Comments

11 comments

  • Giorgio Sironi

    Interesting to see how this can be done with pipeline code (which is not very clear at https://jenkins.io/doc/pipeline/steps/workflow-scm-step/#checkout-general-scm).

    It seems however we are replicating information about the build configuration inside the pipeline definition, replicating attributes like:

             userRemoteConfigs: scm.userRemoteConfigs

    Is there a way to just specify what changes, altering the scm object or making a full copy of it with some customization?

     

    0
  • Rbabzba 123

    I was trying to achieve the SparseCheckout but failing so far, your help would be highly appreciated. It checkout the whole branch instead of specified folder.

    checkout([
            $class: 'GitSCM',
            branches:[[name: '*/branchName']],
            extensions: scm.extensions + [[$class: 'SparseCheckoutPaths'], path:'FolderName'],
            userRemoteConfigs: scm.userRemoteConfigs
        ])
    0
  • Viacheslav Dubrovskyi

    Hi.
    I would like use reference repository with credential. For example from Google Cloud source. Is it possible? Help me please.

    0
  • Christian Schulz

    Not all additional behaviors seems to be supported.

    0
  • Denys Digtiar

    Hi Christian,

    Your comment cannot really be addressed since it lacks any context and information about your environment. If you are CloudBees customer feel free to raise a support ticket, if not please approach the Jenkins community on regular channels (e.g. IRC, user mailing list, Stack Overflow).

    0
  • Patrick Callahan

    I would like to do something like this because I would rather encode as much information about how the build is to be done in the Jenkinsfile as possible-- the only thing I really want to specify in the job itself is the location of the repository.

    My concern is not branch-specific behavior, but certain behaviors (like checking out to a local branch) that we'll need for all of our projects because our build tools expect it.

    Is it still considered a 'workaround' to be 'avoided' in my case? Should I prefer configuring the SCM through the web interface, for some reason? Is it 'not safe' to access the properties of the `scm` variable in this way?

    0
  • Allan Burdajewicz

    Patrick,

    Since GitHub Branch Source 2.2.0 / Bitbucket Branch Source 2.2.0, such advanced behaviors - now known as SCM Traits are configurable at the organization / multibranch level in the UI. You should not need to fiddle with the checkout step anymore.

    0
  • Patrick Callahan

    Thanks, Allan.

    I understand that these things can be configured one-by-one, in the UI. But copying and pasting a template Jenkinsfile for a new project is less manual and less error-prone, which is why I'd rather have that in the instructions for my organization than a bunch of directions about what to click on.

    Is there any reason that using this method is actually bad? (And is there any way to get the GitHub plugin, for example, to use 'Checkout via SSH' declaratively?)

    0
  • Christian Polzer

    Hi there,

    Great article, thank you!

    This is also working for declarative pipeline? I am currently porting a regular "old" jenkinsfile to declarative syntax and suddenly my "maven release " step is not working anymore. It is triggered in case master branch is build.

     

    Thanks in advance!

     

     

    0
  • Allan Burdajewicz

    Hi Christian,

    Yes. This is working with Declarative pipeline too.

    0
  • Thomas Grainger

    I get:

     

    WorkflowScript: 10: Invalid config option "checkout" for agent type "node". Valid config options are [label, customWorkspace] @ line 10, column 13.
                   checkout([

     

    Also I notice that the issue mentioned in this post is now fixed: https://issues.jenkins-ci.org/browse/JENKINS-37658

    0

Please sign in to leave a comment.

About CloudBees Support

Our Support Engineers are available to help with any questions or problems you may have with any of our products.