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

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

    XMLWordPrintable

Details

    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

            balee balee balee added a comment -

            It might sound a bit unorthodox, but really, isn't there a way to solve this properly (from the point of view of Jenkins users), without messy and inconvenient workarounds?

            For example, if a pipeline is saved (on the UI or with CLI or ...), it might be parsed automagically and look for parameters only and do the same with them as if the job was run? Or actually run the job on save but somehow limited to parameter properties only (and hide the run from the history)? Or...

            I'm sure it is not very simple to implement but it is quite a Major issue...

            balee balee balee added a comment - It might sound a bit unorthodox, but really, isn't there a way to solve this properly (from the point of view of Jenkins users), without messy and inconvenient workarounds? For example, if a pipeline is saved (on the UI or with CLI or ...), it might be parsed automagically and look for parameters only and do the same with them as if the job was run? Or actually run the job on save but somehow limited to parameter properties only (and hide the run from the history)? Or... I'm sure it is not very simple to implement but it is quite a Major issue...
            jglick Jesse Glick added a comment -

            it might be parsed automagically and look for parameters only

            That is exactly what this issue proposes (for Declarative Pipeline).

            jglick Jesse Glick added a comment - it might be parsed automagically and look for parameters only That is exactly what this issue proposes (for Declarative Pipeline).
            mcosta Miguel Costa added a comment -

            I guess there is no real chances this gets implemented since it's been more than 3 years since it's open?
            Is there any good way around this without failing the first build but also having to run it manually?

            mcosta Miguel Costa added a comment - I guess there is no real chances this gets implemented since it's been more than 3 years since it's open? Is there any good way around this without failing the first build but also having to run it manually?

            mcosta : From felipecassiors's comment above (slightly simplified), we add this to pipelines:

             

            stage('prepare') {
              steps {
                // Initialize params as envvars, workaround for bug https://issues.jenkins-ci.org/browse/JENKINS-41929
                script { params.each { k, v -> env[k] = v } }
              }
            }

             

            qnerden Quentin Nerden added a comment - mcosta : From felipecassiors 's comment above (slightly simplified), we add this to pipelines:   stage( 'prepare' ) { steps { // Initialize params as envvars, workaround for bug https://issues.jenkins-ci.org/browse/JENKINS-41929 script { params.each { k, v -> env[k] = v } } } }  
            felipecassiors Felipe Santos added a comment -

            qnerden slightly? This is much cleaner and better! Thanks a lot for sharing.

            One important thing to note is that none of the parameters should be included in `environment` section of the pipeline, otherwise changes made during a stage (like this 'prepare' one) won't be retained for all stages.

            felipecassiors Felipe Santos added a comment - qnerden  slightly? This is much cleaner and better! Thanks a lot for sharing. One important thing to note is that none of the parameters should be included in `environment` section of the pipeline, otherwise changes made during a stage (like this 'prepare' one) won't be retained for all stages.

            People

              Unassigned Unassigned
              jglick Jesse Glick
              Votes:
              158 Vote for this issue
              Watchers:
              167 Start watching this issue

              Dates

                Created:
                Updated: