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

Pipelines with parameters always fail to pick up parameters on first run

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major Major
    • None
    • Declarative - 1.2

      Summary:
      The first time a declarative pipeline which makes use of parameters gets run, the link in the Jenkins UI says "Build." This appears to cause the build to run without processing the parameters { } block at all.

      Steps to recreate:
      1. Create a simple Pipeline job in Jenkins, and paste this into it:

      pipeline {
      
          parameters {
              string(name: 'AGENT_NAME', defaultValue: 'linux', description: 'Where to run')
          }
      
          agent {
              label ("${env.AGENT_NAME}")
          }
      
          options {
              buildDiscarder(logRotator(numToKeepStr: '100')) 
              disableConcurrentBuilds()
              timestamps()
          }
      
          stages {
              stage ('Parallel Wrapper') { 
                  steps {
                      sh 'java -version'
                  }
              } // end stage
          } // end stages
      
          post {
              always {
                  echo "ALWAYS --> Runs all the time."
              }
              success {
                  echo "SUCCESS --> Whatever we did, it worked. Yay!"
              }
              failure {
                  echo "FAILURE --> Failed. Womp womp."
              }
          }
      
       }
      

      2. Save the Pipeline, but don't run it yet. Look on the left: the link to start a build says "Build Now." Like this:

      3. Click "Build Now,"

      4. Navigate to the console log for the build you just started. Pretty soon, you'll see this:

      Started by user admin
      [Pipeline] node
      Still waiting to schedule task
      There are no nodes with the label ‘null’
      

      5. I first thought that this was a bug in my Pipeline code, but it's not. Navigate back to the main page for the Pipeline, and look at that Build link again. Notice that it now says "Build with Parameters"

      6. Run the build a second time by clicking "Build with parameters." This time, you'll be prompted to provide, or verify, the AGENT_NAME parameter:

      That's why I'm convinced that the parameters section just isn't being processed at all on first run. I've got a default setting in place, and that default setting will work. But not that first time.

      7. After you've done your second attempt, you might end up here. In which case, you'll need to cancel the still-queued Build #1:

      8. After canceling #1, #2 goes through without issue:

        1. image-2017-09-01-15-05-07-640.png
          540 kB
          Karl Shultz
        2. image-2017-09-01-15-11-25-021.png
          460 kB
          Karl Shultz
        3. image-2017-09-01-15-14-21-893.png
          595 kB
          Karl Shultz
        4. image-2017-09-01-15-16-04-225.png
          467 kB
          Karl Shultz
        5. image-2017-09-01-15-17-54-627.png
          538 kB
          Karl Shultz
        6. image-2017-09-01-15-18-55-946.png
          637 kB
          Karl Shultz

            abayer Andrew Bayer
            kshultz Karl Shultz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: