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

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

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Duplicate
    • Labels:
      None
    • Environment:
    • Similar Issues:
    • Sprint:
      Declarative - 1.2

      Description

      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:

        Attachments

          Issue Links

            Activity

            Hide
            abayer Andrew Bayer added a comment -

            Yup, JENKINS-41929 - but fwiw, params.AGENT_NAME will always return the default value in the first build.

            Show
            abayer Andrew Bayer added a comment - Yup, JENKINS-41929 - but fwiw, params.AGENT_NAME will always return the default value in the first build.
            Hide
            kshultz Karl Shultz added a comment -

            Dagnabbit, sorry about the duplicate. Think I missed it because I was looking at Issues, and not New Features.

            Show
            kshultz Karl Shultz added a comment - Dagnabbit, sorry about the duplicate. Think I missed it because I was looking at Issues, and not New Features.
            Hide
            abayer Andrew Bayer added a comment -

            =)

            Show
            abayer Andrew Bayer added a comment - =)

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                kshultz Karl Shultz
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: