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

Different behavior for pipeline and pre-pipeline jobs for the same plugin regarding preCheckout phase

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • pipeline
    • None

      I've been working on a patch for ws-cleanup-plugin to make it possible to use "Clean workspace before build" in a (declarative) pipeline. Apologies if I have misunderstood things, but I haven't done that much development of Jenkins Plugins before.

      The code in question was a BuildWrapper, but is now SimpleBuildWrapper, to make it compatible with declarative pipelines.
      https://github.com/jenkinsci/ws-cleanup-plugin/pull/49

      When used in a non-pipeline job the wrapper is executed during the preCheckout phase IIUC. That means that it is executed before the job checks out code from SCM. When used in a pipeline job the wrapper is executed after the default checkout from SCM. This can be seen in the logs.

      It took a while for me to understand that the method runPreCheckout() is only being evaluated for non-pipeline builds. Is there a technical reason for this? If not, would it be possible to change this so that runPreCheckout() is evaluated for pipeline builds as well?

      I have managed to work around this by modifying the declarative pipeline to look like this:

      pipeline { 
          agent any
          options {
              skipDefaultCheckout(true)
          }
          stages {
              stage('Build') {
                  steps {
                      preBuildCleanWs {
                          checkout scm
                          echo "Building ${env.JOB_NAME}..."
                      }
                  }
              }
          }
      }
      

      That however doesn't feel intuitive and, as I said in the beginning, this plugin behaves differently in pipeline and non-pipeline jobs by default.
       

            Unassigned Unassigned
            dennisl Dennis Lundberg
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: