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

            jensre orasre added a comment - - edited

            Hi felipecassiors,

            I am having the same issue but using the above workaround didn't work. I have two parameters one of them is a choice that is populated by a list variable. The other one is an empty text field to be populated later. None of them can have a default value.

             

            Thanks

            jensre orasre added a comment - - edited Hi felipecassiors , I am having the same issue but using the above workaround didn't work. I have two parameters one of them is a choice that is populated by a list variable. The other one is an empty text field to be populated later. None of them can have a default value.   Thanks
            felipecassiors Felipe Santos added a comment -

            Try with this:

            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 - Try with this: 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}" } } } }
            jensre orasre added a comment -

            Thanks felipecassiors  for your quick reply. It didn't work too. In my case, I am using the seed job to update the Jenkins pipeline jobs. Once, I run the seed job, the "Build with Parameters" options disappears from the updated pipeline and I then am left with just "build"

             

            It is OK for most of my jobs to just start and stop a job manually to bring the "Build with Parameters" back but the problem is with the scheduled ones. They won't start unless I manually start/stop them first.

            jensre orasre added a comment - Thanks felipecassiors   for your quick reply. It didn't work too. In my case, I am using the seed job to update the Jenkins pipeline jobs. Once, I run the seed job, the "Build with Parameters" options disappears from the updated pipeline and I then am left with just "build"   It is OK for most of my jobs to just start and stop a job manually to bring the "Build with Parameters" back but the problem is with the scheduled ones. They won't start unless I manually start/stop them first.
            menna_khaled menna khaled added a comment -

            hello jensre, what worked for me is: I get the job via API, I get the 'nextBuildNumber' field, then when I upload the jenkinsfile of a job I add to the jenkinsfile a check if the build number is equal to <nextBuildNumber> , then abort the build, this way the button is 'build with parameters' for all the upcoming builds.

            menna_khaled menna khaled added a comment - hello jensre , what worked for me is: I get the job via API, I get the 'nextBuildNumber' field, then when I upload the jenkinsfile of a job I add to the jenkinsfile a check if the build number is equal to <nextBuildNumber> , then abort the build, this way the button is 'build with parameters' for all the upcoming builds.
            adeceuke Antoine added a comment -

            Hi jensre , in your case this is easier.

            In your seed job, include in your pipeline job definition the parameters:

            pipelineJob('YourJob')

            {     parameters \{stringParam('First param')}

                parameters {stringParam('Second param')}

            Then the "Build with Parameters" will be available after the seed job creates/updates your pipeline jobs.

            adeceuke Antoine added a comment - Hi jensre , in your case this is easier. In your seed job, include in your pipeline job definition the parameters: pipelineJob('YourJob') {     parameters \{stringParam('First param')}     parameters {stringParam('Second param')} Then the "Build with Parameters" will be available after the seed job creates/updates your pipeline jobs.

            People

              Unassigned Unassigned
              jglick Jesse Glick
              Votes:
              161 Vote for this issue
              Watchers:
              172 Start watching this issue

              Dates

                Created:
                Updated: