Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-49142

Be able to customize checkout as "options" in declarative pipeline

    • Declarative backlog

      Right now it's very hard to use a declarative pipeline if you need to customize how the Git checkout is done, specially when combined with dockerized builds.

      The only approach I could find currently is to do something like:

      pipeline {
          // If docker is used here, the image needs to have Git installed
          agent any
          stages {
              stage("Checkout") {
                  steps {
                      checkout([
                          $class: 'GitSCM',
                          branches: scm.branches,
                          extensions: scm.extensions + [[$class: 'CleanCheckout']],
                          userRemoteConfigs: scm.userRemoteConfigs
                      ])
      
                  }
              }
              stage("Another") {
                  agent {
                      docker {
                          // This is needed so the previous checkout is used
                          reuseNode true
                      }
                  }
                  // ...
              }
          }
      }
      

      And then I have to copy the docker agent to all subsequent stages, which for very long and complex pipelines and specially ones using a lot of docker options, is super annoying and error prone. Also, the `checkout()` call needs some special permissions one need to approve in jenkins first, when all I want is to use some extension.

      So, doing this is very complex and error prone. Because of this, it would be nice (and make sense) if there is any way to customize the initial checkout instead of having to make it as a stage.

      Something like:

      pipeline {
          options {
              checkoutExtensions ['CleanCheckout']
          }
      }
      

      Or maybe being able to just call `checkout()` in options, but if that means needing special permissions, it would also be not ideal.

          [JENKINS-49142] Be able to customize checkout as "options" in declarative pipeline

          Leandro Lucarella added a comment - BTW, the permissions part is mentioned here: https://support.cloudbees.com/hc/en-us/articles/226122247-How-to-Customize-Checkout-for-Pipeline-Multibranch-

          Hi lucasocio

          I'm working in this ticket, would you mind to take a look into it?

          Github  PR: https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/307

          Jose Blas Camacho Taboada added a comment - Hi lucasocio ,  I'm working in this ticket, would you mind to take a look into it? Github  PR:  https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/307

          This is sorely needed.  It's a pity to see that the PR for it died on the vine. It seems the perfect became the enemy of the good perhaps.

          In any case, all of the zillions of work-arounds (git command in sh step, scm command in stage steps, etc.) for updating submodules once the per-stage default scm checkout is done don't work if the Dockerfile that the stage is supposed to use for it's agent is in the submodule that needs to be checked-out/updated.

          Brian J Murrell added a comment - This is sorely needed.  It's a pity to see that the PR for it died on the vine. It seems the perfect became the enemy of the good perhaps. In any case, all of the zillions of work-arounds ( git command in sh step, scm command in stage steps, etc.) for updating submodules once the per-stage default scm  checkout is done don't work if the Dockerfile  that the stage is supposed to use for it's agent is in the submodule that needs to be checked-out/updated.

            Unassigned Unassigned
            lucasocio Leandro Lucarella
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: