Parameter

Jenkins Job: Building with Parameters and Extended Choice Parameter

0 Comments

Introduction

Jenkins is an open-source continuous integration (CI) server. Jenkins server helps to automate the software development parts like building, testing, and deploying. Thousands of development teams use the widely used DevOps tool Jenkins.

One of its many features is the ability to create customize builds using parameters. While the basic parameters like string, boolean, and choice parameters cover a wide range of use cases the Extended Choice Parameter plugin offers additional versatility. In this blog post, we’ll explore the Jenkins parameter and Extended Choice Parameter.

Jenkins Build Parameters

Jenkins uses parameters to send custom values into jobs at the time of trigger. You can dynamically control the behavior of your Jenkins jobs with these settings. These variables are defined in the job setup and are accessible through environment variables when the job is running.

Parameter’s role in build process

  • Customizing Builds: Users can specify custom values for parameters, which can change how the build behaves. One way to use a parameter would be to select a deployment environment (such as DEV, QA, or PROD).
  • Passing User Input: The build can receive user input like Versions, branches, or configurations that the build should utilize can be specified using this.
  • Reusability: A Jenkins task can be utilized more than once by using parameters. For example, depending on the input parameter, the same job can deploy to many environments.
  • Dynamic Decision Making: Decisions can be made dynamically during the build process by utilizing parameters. A parameter could decide, for instance, whether code analysis, test runs, or stage skips are carried out.
  • Integration with Other Jobs: Jenkins jobs can be integrated more easily with parameters. Complex workflows are made possible by the ability to activate a downstream operation with parameters given from an upstream job.

Standard Parameters

Some common types of Jenkins parameters:

  • Boolean Parameter: A checkbox that represents true or false.
  • Choice Parameter: A drop-down menu with predefined options.
  • Credentials Parameter: Used to select credentials stored in Jenkins.
  • File Parameter: Allows users to upload a file to be used by the job.
  • Password Parameter: Used to securely input passwords.
  • Run Parameter: Allows you to select a specific build of another job.
  • String Parameter: Allows users to enter a string of text.
  • Multi-line String Parameter: Allows users to input and handle multi-line strings within their builds.

To learn more about Jenkins parameters, go to Jenkins Wiki page.

Jenkins Extended Choice Parameter

With the help of the Jenkins plugin Extended Choice Parameter, you can give your Jenkins jobs more robust and adaptable input choices. It adds support for multiple selections, dynamic options, and more intricate setups to the conventional choice parameter.

Key Features

  • Allows users to select multiple values from a list.
Jenkins Extended Parameter
  • Dynamic Options: Scripts or outside sources can be used to produce options dynamically.
Picture3
  • Type Customization: Accommodates many input formats, including radio buttons, checkboxes, and multiple selections.
  • Property File Support: Allows loading options from property files.
Picture4
  • Json Parameter Support
Picture5

Installation of Extended Choice Parameter Plugin

Prerequisite: Jenkins server should be installed and up. For any help regarding Jenkins setup please visit https://dasfascination.com/jenkins-server-setup-and-uses/

Installation:

  • Navigate to “Manage Jenkins” > “Manage Plugins”.
  • Select the “Available Plugin” tab.
  • Search for “Extended Choice Parameter”.
  • Check the box next to the plugin and click “Install”
  • To Verify installation Navigate to ‘Installed Plugin’ and search Extended choice parameter.
Picture6

Use of this parameter:

A recent automation project using the Appium robot framework requires that user stories be supplied with a multi-select option. The user stories will be executed in accordance with the tester’s preference (Single or Multiple). This scheduling with extended parameter choice option will be explained in this section.

Picture7
  • Create a New Job with Freestyle Option.
Picture8
  • Click on “Add Parameter” and select “Extended Choice Parameter”.
  • Set Up the Parameter by value.
Picture9

Build Step using this parameter:

Robot framework support execution of test cases based on tags, you can use tag to combine related test cases, show their priority or status, and exclude them from execution. Below is the example to execute test cases with tag “one” in any file.  

# robot --include one . 

Now to include tags on random basis (single, multi) as per the tester requirement, there is a need to parse the tester inputs. Below are the build steps for the same.

set USER_STORY=%USER_STORY:,= --include %
set USER_STORY=%USER_STORY:"=%
set USER_STORY=--include %USER_STORY%
robot %USER_STORY%  .\TestCases\.

The console output of the execution when tester chooses LIVE_ON_NOW_RAIL and CONTINUE_WATCHING

C:\Users\user\.jenkins\workspace\Automation_team>set USER_STORY="LIVE_ON_NOW_RAIL --include CONTINUE_WATCHING" 
C:\Users\user\.jenkins\workspace\Automation_team>set USER_STORY=LIVE_ON_NOW_RAIL --include CONTINUE_WATCHING 
C:\Users\user\.jenkins\workspace\Automation_team>set USER_STORY=--include LIVE_ON_NOW_RAIL --include CONTINUE_WATCHING 
C:\Users\user\.jenkins\workspace\Automation_team>robot --include LIVE_ON_NOW_RAIL --include CONTINUE_WATCHING  \TestCases\. 

Conclusion

The extended choice parameter plugin along with standard parameters of enhances flexibility, which permits more intricate parameter setups. Whether you need multiple selections, dynamic options, or custom input types, this plugin can help streamline your CI/CD processes. See how it can enhance your build procedures by giving it a try in your upcoming Jenkins job.

Limitation of Build with Parameter

There is no method to pass parameters when a build is started using build triggers. This covers periodic builds, downstream builds, and SCM polling. Rather, the string, boolean, and choice parameters will be utilized with the supplied default values.

This limitation can be eliminated if Jenkins developer include a loop parameter and execute the build step commands in a loop.

Leave a Reply

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

Related Posts