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

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

    XMLWordPrintable

    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
            ip1981 Igor Pashev added a comment -

            > Just define the trigger, parameters, or other job properties directly on the job, as you would have for freestyle. This works for both inline scripts and scripts from SCM

            Looks like it really works!

             

            Show
            ip1981 Igor Pashev added a comment - > Just define the trigger, parameters, or other job properties directly on the job, as you would have for freestyle. This works for both inline scripts and scripts from SCM Looks like it really works!  
            Hide
            ruhkopf Patrick Ruhkopf added a comment - - edited

            There seems to be a more critical issue when using parameterized, declarative pipelines within shared libraries and multi-branch projects. When there were modifications and a change is pushed from SCM, then the build fails immediately with the following exception:

            java.lang.IllegalArgumentException: Null value not allowed as an environment variable: APPLICATION
             at hudson.EnvVars.put(EnvVars.java:359)
             at hudson.model.StringParameterValue.buildEnvironment(StringParameterValue.java:59)
             at hudson.model.ParametersAction.buildEnvironment(ParametersAction.java:145)
             at hudson.model.Run.getEnvironment(Run.java:2365)
             at org.jenkinsci.plugins.workflow.job.WorkflowRun.getEnvironment(WorkflowRun.java:513)
             at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:106)
             at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:120)
             at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:303) 

            When the pipeline is in this state, the only fix is to manually trigger it with "Run with parameters". I can't use any of the workarounds suggested here, because even when I update the Jenkinsfile to not call the shared pipeline and just print a single "echo hello world", it still fails right away. Any suggestions?

            Does this belong here in this issue or should I open a new one?

            Show
            ruhkopf Patrick Ruhkopf added a comment - - edited There seems to be a more critical issue when using parameterized, declarative pipelines within shared libraries and multi-branch projects. When there were modifications and a change is pushed from SCM, then the build fails immediately with the following exception: java.lang.IllegalArgumentException: Null value not allowed as an environment variable: APPLICATION at hudson.EnvVars.put(EnvVars.java:359) at hudson.model.StringParameterValue.buildEnvironment(StringParameterValue.java:59) at hudson.model.ParametersAction.buildEnvironment(ParametersAction.java:145) at hudson.model.Run.getEnvironment(Run.java:2365) at org.jenkinsci.plugins.workflow.job.WorkflowRun.getEnvironment(WorkflowRun.java:513) at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:106) at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:120) at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:303) When the pipeline is in this state, the only fix is to manually trigger it with "Run with parameters". I can't use any of the workarounds suggested here, because even when I update the Jenkinsfile to not call the shared pipeline and just print a single "echo hello world", it still fails right away. Any suggestions? Does this belong here in this issue or should I open a new one?
            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}' " } } } } } }

              People

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

                Dates

                • Created:
                  Updated: