0
0
Jenkinsdevops~30 mins

Parameters block declaration in Jenkins - Mini Project: Build & Apply

Choose your learning style9 modes available
Jenkins Pipeline: Parameters Block Declaration
📖 Scenario: You are setting up a Jenkins pipeline for a simple project. You want to allow users to provide input parameters when they start the pipeline. This helps customize the build process based on user choices.
🎯 Goal: Build a Jenkins pipeline script that declares a parameters block with specific input parameters. This will let users enter values before the pipeline runs.
📋 What You'll Learn
Declare a parameters block in the Jenkins pipeline script
Add a string parameter named BRANCH_NAME with default value main
Add a boolean parameter named RUN_TESTS with default value true
Add a choice parameter named DEPLOY_ENV with choices dev, qa, prod
Print the values of all parameters in the pipeline
💡 Why This Matters
🌍 Real World
Jenkins pipelines often need user input to decide which branch to build, whether to run tests, or where to deploy. Parameters block lets users provide this input easily.
💼 Career
Knowing how to declare and use parameters in Jenkins pipelines is essential for DevOps engineers to create flexible and user-friendly CI/CD workflows.
Progress0 / 4 steps
1
Create the basic Jenkins pipeline script
Create a Jenkins pipeline script with a pipeline block and an empty parameters block inside pipeline. Use agent any to run on any available agent.
Jenkins
Need a hint?

The parameters block goes inside the pipeline block but before stages.

2
Add string and boolean parameters
Inside the parameters block, add a string parameter named BRANCH_NAME with default value main, and a boolean parameter named RUN_TESTS with default value true.
Jenkins
Need a hint?

Use string(name: '', defaultValue: '', description: '') and booleanParam(name: '', defaultValue: , description: '') inside parameters.

3
Add a choice parameter for deployment environment
Add a choice parameter named DEPLOY_ENV inside the parameters block. It should have choices dev, qa, and prod.
Jenkins
Need a hint?

Use choice(name: '', choices: ['option1', 'option2'], description: '') inside parameters.

4
Print all parameter values in the pipeline
Inside the steps block of the Example stage, add echo statements to print the values of BRANCH_NAME, RUN_TESTS, and DEPLOY_ENV parameters.
Jenkins
Need a hint?

Use echo "BRANCH_NAME: ${params.BRANCH_NAME}" to print parameter values inside steps.