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

External way to set default parameter values for a pipeline job


    • Similar Issues:


      As a user, I would like to reuse a Jenkinsfile across different Jenkins installations and being capable of setting parameters inside a Jenkinsfile, with default values that are loaded from some other source.

      For example:

      I have a project that is built on two different Jenkins installations that are running on different environments. For security reasons the environments needs to be separate. Each environment has some differences that I need to set in the parameters, in order to be able to run the job. At the moment I am obligated to use "ifs" based on the env.JOB_NAME in order to change each defaultValue for every parameter. 

      Not only this, but I also need to use a cron trigger for this pipeline, which forcibly uses the default values to run it.

      I've tried many hacks to make the defaults to be loaded from some other place, but they don't play nicely with the way Jenkins constructs the "Build with Parameters" form. The Jenkinsfile is not pre-executed neither pre-loaded in order to construct this form, so even if I find a way to dynamically set the defaultValue for every parameter, this value will not be kept.

      So, I believe Jenkins should have one of the following solutions:

      • A way to preload the Jenkinsfile from the source repository, without having to run through the steps, including running part of the Jenkinsfile to be able to dynamically set default values for the parameters (ex.: getting values from env and using as defaultValue in the preload).
      • A way to set the defaults that is separate from the Jenkinsfile - could be directly in the job configuration



          hgfxng Herbert Fischer created issue -
          mjdetullio Matthew DeTullio made changes -
          Field Original Value New Value
          Component/s multi-branch-project-plugin (not Pipeline) [ 21127 ]
          mjdetullio Matthew DeTullio made changes -
          Assignee Matthew DeTullio [ mjdetullio ]
          svanoort Sam Van Oort made changes -
          Priority Blocker [ 1 ] Minor [ 4 ]
          bentzy Bentzy Sagiv made changes -
          Comment [ My solution is a following:

          {{at jenkinsfile.pipeline.properties:}}
           {{at Jenkinsfile :}}
          node {

             def props = readProperties file: "<YOUR_PATH>/jenkinsfile.pipeline.properties"

             def distribution= props['distribution_property']
             def tag= props['tag_property']

                   string(name: 'distribution', defaultValue: 'testing', description: 'apt distribution'),
                   string(name: 'tag', defaultValue: 'RanByJenkins_default', description: 'just a tag')

             echo "distribution: $distribution"
             echo "tag: $tag"
           Values from properties file will not be overriden by default values NOR by values from UI!!!
           To make values overridable omit them from properties file.
           Then default will be taken or value from GUI - if it was changed from the default.

          Is that what you need?



            • Assignee:
              hgfxng Herbert Fischer
            • Votes:
              9 Vote for this issue
              11 Start watching this issue


              • Created: