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

Offer "Build with Parameters" on first build when declarative Jenkinsfile found

    Details

    • Similar Issues:

      Description

      By default a branch project will automatically run the first build, with no parameters, so params will just pick up any default values. You have the option to suppress the automatic first build, but this does not give you any way to enter parameters for it (at least in the UI; perhaps possible via CLI/REST), since Jenkins does not know what the parameters are going to be until it starts running. But in the case of Declarative we could in principle inspect the Jenkinsfile when the branch project is created (via SCMFileSystem) and determine the parameter definitions by static parsing without actually running.

      More generally, if Declarative is in use and there are properties, we could set all the project properties when the branch project is created, even if the first build is run automatically. (Though I would suggest that the automatic first build should be automatically suppressed if there is a ParametersDefinitionProperty.)

        Attachments

          Issue Links

            Activity

            Hide
            abayer Andrew Bayer added a comment -

            Patrick Ruhkopf - open a new ticket and make sure to include your full reproduction case. I assume you don't have a default value set for the parameter in question?

            Show
            abayer Andrew Bayer added a comment - Patrick Ruhkopf - open a new ticket and make sure to include your full reproduction case. I assume you don't have a default value set for the parameter in question?
            Hide
            famod Falko Modler added a comment -

            I am also affected by this:

            • Jenkinsfile from SCM
            • string parameter with defaultValue
            • value is accessed via ${params.[...]}
            • changed defaultValue is only picked up in the second build, not right away
            Show
            famod Falko Modler added a comment - I am also affected by this: Jenkinsfile from SCM string parameter with defaultValue value is accessed via ${params. [...] } changed defaultValue is only picked up in the second build, not right away
            Hide
            ifernandezcalvo Ivan Fernandez Calvo added a comment - - edited

            The workaround seems not valid on the latest version of declarative pipeline, even do you use params to declare the environment variable the variable is not defined

            • Jenkins core 2.153
            • Declarative Pipeline 1.3.3

            Steps to replicate the issue:

            • Create a Jenkinsfile like the following in a repo
            • Create a multibranch pipeline that uses this repo and this Jenkinsfile
            • Create a PR
            • Check the logs of the pipeline and you could see the issue, the variable is not defined on parallel stages
            #!/usr/bin/env groovy
            
            pipeline {
              agent none
              options {
                timeout(time: 1, unit: 'HOURS')
                buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30'))
                timestamps()
                ansiColor('xterm')
                disableResume()
                durabilityHint('PERFORMANCE_OPTIMIZED')
              }
              parameters {
                string(name: 'GO_VERSION', defaultValue: "1.10.3", description: "Go version to use.")
              }
              stages {
                stage('Initializing'){
                  agent { label 'linux && immutable' }
                  options { skipDefaultCheckout() }
                  environment {
                    GO_VERSION = "${params.GO_VERSION}"
                  }
                  stages {
                    stage('It works') {
                      steps {
                        sh "echo '${GO_VERSION}'"
                      }
                    }
                  }
                  stage('Test') {
                    failFast true
                    parallel {
                      stage('Fail 01') {
                        steps {
                          sh "echo '${GO_VERSION}'"
                        }
                      }
                      stage('Fail 02') {
                        steps {
                          sh "echo '${GO_VERSION}'"
                        }
                      }
                    }
                }
              }
            }
            

            This works

            pipeline {
              agent none
              options {
                timeout(time: 1, unit: 'HOURS')
                buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30'))
                timestamps()
                ansiColor('xterm')
                disableResume()
                durabilityHint('PERFORMANCE_OPTIMIZED')
              }
              parameters {
                string(name: 'GO_VERSION', defaultValue: "1.10.3", description: "Go version to use.")
              }
              stages {
                stage('Initializing'){
                  agent { label 'linux && immutable' }
                  options { skipDefaultCheckout() }
                  environment {
                    GO_VERSION = "${params.GO_VERSION}"
                  }
                  stages {
                    stage('It works') {
                      steps {
                        sh "echo '${GO_VERSION}'"
                      }
                    }
                  }
                  stage('Test') {
                    failFast true
                    parallel {
                      stage('Fail 01') {
                  environment {
                    GO_VERSION = "${params.GO_VERSION}"
                  }
                        steps {
                          sh "echo '${GO_VERSION}'"
                        }
                      }
                      stage('Fail 02') {
                  environment {
                    GO_VERSION = "${params.GO_VERSION}"
                  }
                        steps {
                          sh "echo '${GO_VERSION}'"
                        }
                      }
                    }
                }
              }
            }
            
            Show
            ifernandezcalvo Ivan Fernandez Calvo added a comment - - edited The workaround seems not valid on the latest version of declarative pipeline, even do you use params to declare the environment variable the variable is not defined Jenkins core 2.153 Declarative Pipeline 1.3.3 Steps to replicate the issue: Create a Jenkinsfile like the following in a repo Create a multibranch pipeline that uses this repo and this Jenkinsfile Create a PR Check the logs of the pipeline and you could see the issue, the variable is not defined on parallel stages #!/usr/bin/env groovy pipeline { agent none options { timeout(time: 1, unit: 'HOURS' ) buildDiscarder(logRotator(numToKeepStr: '20' , artifactNumToKeepStr: '20' , daysToKeepStr: '30' )) timestamps() ansiColor( 'xterm' ) disableResume() durabilityHint( 'PERFORMANCE_OPTIMIZED' ) } parameters { string(name: 'GO_VERSION' , defaultValue: "1.10.3" , description: "Go version to use." ) } stages { stage( 'Initializing' ){ agent { label 'linux && immutable' } options { skipDefaultCheckout() } environment { GO_VERSION = "${params.GO_VERSION}" } stages { stage( 'It works' ) { steps { sh "echo '${GO_VERSION}' " } } } stage( 'Test' ) { failFast true parallel { stage( 'Fail 01' ) { steps { sh "echo '${GO_VERSION}' " } } stage( 'Fail 02' ) { steps { sh "echo '${GO_VERSION}' " } } } } } } This works pipeline { agent none options { timeout(time: 1, unit: 'HOURS' ) buildDiscarder(logRotator(numToKeepStr: '20' , artifactNumToKeepStr: '20' , daysToKeepStr: '30' )) timestamps() ansiColor( 'xterm' ) disableResume() durabilityHint( 'PERFORMANCE_OPTIMIZED' ) } parameters { string(name: 'GO_VERSION' , defaultValue: "1.10.3" , description: "Go version to use." ) } stages { stage( 'Initializing' ){ agent { label 'linux && immutable' } options { skipDefaultCheckout() } environment { GO_VERSION = "${params.GO_VERSION}" } stages { stage( 'It works' ) { steps { sh "echo '${GO_VERSION}' " } } } stage( 'Test' ) { failFast true parallel { stage( 'Fail 01' ) { environment { GO_VERSION = "${params.GO_VERSION}" } steps { sh "echo '${GO_VERSION}' " } } stage( 'Fail 02' ) { environment { GO_VERSION = "${params.GO_VERSION}" } steps { sh "echo '${GO_VERSION}' " } } } } } }
            Hide
            sbussetti steve bussetti added a comment -

            Has there been any traction on this?  Honestly if someone could point me at the code responsible for reading the Jenkinsfile from the scm I could write a simple plugin that just adds a "Refresh Job Definition" button to the sidebar of a job.

            Most of the folks I see run into this are less concerned with the first-time triggered build than they are about being unable to modify new parameters after updating a particular job which means they're manually executing a Pipeline.  

            Show
            sbussetti steve bussetti added a comment - Has there been any traction on this?  Honestly if someone could point me at the code responsible for reading the Jenkinsfile from the scm I could write a simple plugin that just adds a "Refresh Job Definition" button to the sidebar of a job. Most of the folks I see run into this are less concerned with the first-time triggered build than they are about being unable to modify new parameters after updating a particular job which means they're manually executing a Pipeline.  
            Hide
            hkawashi Hideaki Kawashima added a comment - - edited

            Is this bug known to the person in charge ?
            Are you already working on countermeasures ?

            The specification that can specify the default value in parameters block is broken. Various provisional workarounds are listed, but they will fail immediately.
            As mentioned above, re-definition in the environment block is not possible in parallel execution. Script compilation fails if the number of parameters defined in the parameters block is large or the script is slightly larger. Expecting a first build with default settings defined in parameters block for post-commit processing, but we have to go to the build manually after failed. (This breaks automate execution for build pipeline)

            As you know, there are many different builds in the CI environment for post-commit processing. Rerunning them one by one manually will greatly impair the significance of the existence of a CI environment that is designed to reduce time and effort.

            I'd like to see clear countermeasures or workarounds soon.
            Thank you.

            Show
            hkawashi Hideaki Kawashima added a comment - - edited Is this bug known to the person in charge ? Are you already working on countermeasures ? The specification that can specify the default value in parameters block is broken. Various provisional workarounds are listed, but they will fail immediately. As mentioned above, re-definition in the environment block is not possible in parallel execution. Script compilation fails if the number of parameters defined in the parameters block is large or the script is slightly larger. Expecting a first build with default settings defined in parameters block for post-commit processing, but we have to go to the build manually after failed. (This breaks automate execution for build pipeline) As you know, there are many different builds in the CI environment for post-commit processing. Rerunning them one by one manually will greatly impair the significance of the existence of a CI environment that is designed to reduce time and effort. I'd like to see clear countermeasures or workarounds soon. Thank you.

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                jglick Jesse Glick
              • Votes:
                103 Vote for this issue
                Watchers:
                114 Start watching this issue

                Dates

                • Created:
                  Updated: