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

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

              Created:
              Updated: