0
0
Jenkinsdevops~30 mins

String, boolean, and choice parameters in Jenkins - Mini Project: Build & Apply

Choose your learning style9 modes available
Jenkins Pipeline with String, Boolean, and Choice Parameters
📖 Scenario: You are setting up a Jenkins pipeline job that needs user input before running. The inputs include a text string, a yes/no choice, and a selection from a list. This helps customize the build process.
🎯 Goal: Build a Jenkins pipeline script that defines three parameters: a string parameter called ENVIRONMENT, a boolean parameter called RUN_TESTS, and a choice parameter called DEPLOY_REGION. Then, use these parameters in the pipeline to print their values.
📋 What You'll Learn
Create a string parameter named ENVIRONMENT with default value development
Create a boolean parameter named RUN_TESTS with default value true
Create a choice parameter named DEPLOY_REGION with options us-east, us-west, and eu-central
Print the values of all three parameters in the pipeline
💡 Why This Matters
🌍 Real World
Jenkins pipelines often require user inputs to customize builds, such as choosing environments, toggling tests, or selecting deployment regions.
💼 Career
Knowing how to use parameters in Jenkins pipelines is essential for DevOps engineers to create flexible and interactive CI/CD workflows.
Progress0 / 4 steps
1
Define the ENVIRONMENT string parameter
Create a Jenkins pipeline script that defines a string parameter called ENVIRONMENT with the default value development inside the parameters block.
Jenkins
Need a hint?

Use string(name: 'ENVIRONMENT', defaultValue: 'development', description: 'Target environment') inside the parameters block.

2
Add the RUN_TESTS boolean parameter
Add a boolean parameter called RUN_TESTS with the default value true inside the existing parameters block.
Jenkins
Need a hint?

Use booleanParam(name: 'RUN_TESTS', defaultValue: true, description: 'Run tests before deploy') inside the parameters block.

3
Add the DEPLOY_REGION choice parameter
Add a choice parameter called DEPLOY_REGION with options us-east, us-west, and eu-central inside the parameters block.
Jenkins
Need a hint?

Use choice(name: 'DEPLOY_REGION', choices: ['us-east', 'us-west', 'eu-central'], description: 'Deployment region') inside the parameters block.

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

Use echo "ENVIRONMENT: ${params.ENVIRONMENT}", echo "RUN_TESTS: ${params.RUN_TESTS}", and echo "DEPLOY_REGION: ${params.DEPLOY_REGION}" inside the steps block.