How does Jenkins read dynamic parameters?

Jenkins can read dynamic parameters using plugins.

  1. Firstly, make sure you have installed the “Parameterized Build” plugin. You can find and install it in “Manage Jenkins” -> “Manage Plugins” on the Jenkins homepage.
  2. Open the configuration page in your Jenkins project.
  3. Under the “Build” section in the “General” category, click on the drop-down menu for “Add Parameter” and select “Choice Parameter”.
  4. In the “Name” field, enter the name of the parameter, for example, “dynamic parameter”.
  5. In the “Choices” field, enter the different options you wish to provide, separating them with commas, for example “option1, option2, option3”.
  6. Optionally, enter the default value in the “Default Value” field.
  7. Click on the “Advanced” button, then in the “Script” section under the “Advanced” section, enter a Groovy script to dynamically generate options. For example, you can use the following script to generate date options:
def today = new Date()
def tomorrow = today + 1
def twoDaysLater = today + 2
return [today, tomorrow, twoDaysLater].collect { date ->
    date.format("yyyy-MM-dd")
}
  1. Click “Save” to save the configuration.

Your Jenkins project will now be able to read dynamic parameters during the build, allowing users to choose a value from the provided options. If you use a Groovy script to generate the options, a new set of options will be generated every time the build is run.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds