VOOZH about

URL: https://www.geeksforgeeks.org/software-testing/jenkins-build-parameters/

⇱ Jenkins Build Parameters - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Jenkins Build Parameters

Last Updated : 29 Jan, 2026

Build parameters in Jenkins allow you to define variables that can be set by the user when triggering a job. These parameters can include environment configurations, test case arguments, or any other dynamic values needed for the build process.


For instance, if you have a Jenkins job that triggers an automation test suite, you can parameterize the environment in which the test is executed (e.g., dev, stage, or QA). This allows you to run the same set of tests in multiple environments without duplicating the job configurations.

Types of Build Parameters

String Parameter:

  • A simple text box where you can enter a custom string value.
  • Example: Enter the version number for the software you want to deploy.

Boolean Parameter:

  • A checkbox that allows users to toggle between true and false.
  • Example: Enable or disable a specific feature in the build process.

Choice Parameter:

  • Provides a dropdown list of predefined options for the user to select from.
  • Example: Select the environment for deployment (e.g., development, staging, production).

File Parameter:

  • Allows users to upload a file, such as a configuration file or artifact, during the build process.

Password Parameter:

  • Masks the input for sensitive information, such as passwords or API keys.
  • These parameters can be configured with default values, which help guide the user when they are triggering the job. For instance, you might provide a default environment value that the user can change if needed.

How to Add Build Parameters to a Job?

Adding build parameters is a straightforward process in Jenkins. Here's how to do it:

1. Create a New Job: When you create a new Jenkins job or configure an existing one, navigate to the job's configuration section.

2. Enable Parameterization: Check the option called "This project is parameterized." This will enable the "Add Parameter" option.

3. Add Parameters: Click "Add Parameter" and select the type of parameter you want to use (e.g., string, choice, boolean). For each parameter, provide:

  • Name: A unique identifier for the parameter.
  • Default Value (optional): A default value for the parameter.

Description (optional): A brief explanation of the parameter to help the user understand what input is required.

After saving the configuration, Jenkins will prompt users to provide values for the parameters when they click the Build with Parameters button.

Using Build Parameters in the Build Steps

Once the parameters are configured, you can use them in the build steps. To reference a parameter, use the following syntax:

Windows: %PARAMETER_NAME%

Unix/Linux: ${PARAMETER_NAME}

For example, if you define a string parameter for the environment, you can use it in a build step like this:

echo "Building for environment ${ENVIRONMENT}"

During the build process, Jenkins will replace ${ENVIRONMENT} with the value selected by the user (e.g., dev, stage, or QA).

Example: Creating a Job with Build Parameters

1. Create a Job:

  • Start by creating a new job in Jenkins and select "Freestyle Project."
  • In the General section, check "This project is parameterized."
  • Click on "Add Parameter" and choose String Parameter for the username and Choice Parameter for the environment.

2. Configure Parameters:

  • For the String Parameter, name it "USERNAME" and provide a default value like "Rakesh Fardhan."
  • For the Choice Parameter, name it "ENVIRONMENT" and provide options like dev, stage, and QA.

3. Add Build Step:

  • Add a build step, such as Execute Windows Batch Command, and use the parameters in the script:
echo "Hello ${USERNAME}, you have selected the ${ENVIRONMENT} environment."

4. Run the Job:

  • When triggering the job, Jenkins will prompt you to enter or select values for the parameters. If no value is provided, the default will be used.
  • For example, if the user selects "QA" for the environment and provides a custom username,

Output might be:

Hello James, you have selected the QA environment.

Common Use Cases for Build Parameters

👁 common_use_cases_for_build_parameters

1. Environment-Specific Builds:

  • Often, you need to deploy or test applications in different environments (e.g., dev, staging, production).
  • Instead of creating separate jobs for each environment, you can create a single job and use a Choice Parameter to select the environment dynamically.

2. Versioning:

  • When deploying a specific version of software (e.g., a WAR or JAR file), you can use a String Parameter to specify the version number.
  • This eliminates the need to create multiple jobs for each version.

3. Feature Toggle:

  • You may need to enable or disable certain features during deployment.
  • A Boolean Parameter can be used to toggle these features on or off.

4. File Upload:

  • If you need to upload specific files or artifacts for the build, a File Parameter can be used.
  • The user can upload a file directly through the Jenkins interface during job execution.

Example of Build Parameters

  • Create a new job
👁 Screenshot-2024-12-02-152501
1. create a new job
  • Continue with the freestyle Project and Clique okay.
  • Select these bellow option:
👁 Select option:
Select option
  • Select the parameter as you want with clicking the button add parameters section.
👁 Select the parameter as you want
Select the parameter as you want
  • We will choose the String Parameters
  • add the particular values for the String parameters
👁 add the particular values
add the particular values
  • Take the particular script and add to the Execute Windows batch command
echo "Hello, %USERNAME%! You have selected the XENVIRONMENT% environment."
👁 add to the Execute Windows batch command
add to the Execute Windows batch command
  • Give the String parameters value like these :
👁 Give the String parameters value like these :
Give the String parameters value like these
  • and add the choice parameter value which is :
👁 and add the choice parameter value which is
and add the choice parameter value
  • After that save these and Run the project with the option in the left which is Build with parameters:
  • It will automatically trigger the Job. and the project parameters job will display and click on the build button:
👁 click on the build button
click on the build button

It will give the "Console output" which are like the bellow:

👁 Console output
Console output

You can try with the Different Environment with the various value which are available it will also change the Console Output with the same when running.

Comment
Article Tags:

Explore