A new DevOps Engineer has joined the team and he will be assigned some Jenkins related tasks. Before that, the team wanted to test a simple parameterized job to understand basic functionality of parameterized builds. He is given a simple parameterized job to build in Jenkins. Please find more details below:
Click on the Jenkins button on the top bar to access the Jenkins UI. Login using username admin and password Adm!n321.
- Create a
parameterizedjob which should be named asparameterized-job - Add a
stringparameter namedStage; its default value should beBuild. - Add a
choiceparameter namedenv; its choices should beDevelopment,StagingandProduction. - Configure job to execute a shell command, which should echo both parameter values (you are passing in the job).
- Build the Jenkins job at least once with choice parameter value
Developmentto make sure it passes.Note: - You might need to install some plugins and restart Jenkins service. So, we recommend clicking on
Restart Jenkins when installation is complete and no jobs are runningon plugin installation/update page i.eupdate centre. Also, Jenkins UI sometimes gets stuck when Jenkins service restarts in the back end. In this case, please make sure to refresh the UI page. - For these kind of scenarios requiring changes to be done in a web UI, please take screenshots so that you can share it with us for review in case your task is marked incomplete. You may also consider using a screen recording software such as loom.com to record and share your work.
Step 1: Access the Jenkins UI
Click the Jenkins button on the top bar of your KodeKloud lab environment. This opens the Jenkins UI in a new tab.
Log in with:
| Field | Value |
|---|---|
| Username | admin |
| Password | Adm!n321 |
You'll land on the Jenkins dashboard.
Step 2: Create the Job
From the dashboard:
- Click New Item in the left sidebar
- In the Enter an item name field, type:
parameterized-job - Select Freestyle project
- Click OK
You'll be taken to the job configuration page.
Step 3: Enable Parameterized Build
At the top of the configuration page, in the General section:
- Check the box: ☑️ This project is parameterized
Once checked, an Add Parameter dropdown button will appear. This is where we'll define our parameters.
Step 4: Add the String Parameter (Stage)
- Click Add Parameter → select String Parameter
- Fill in the fields:
| Field | Value |
|---|---|
| Name | Stage |
| Default Value | Build |
| Description | (optional) Enter the stage name
|
What is a String Parameter?
It accepts free-form text input. You can set a default value that pre-fills the input box when a user runs the job.
Step 5: Add the Choice Parameter (env)
- Click Add Parameter again → select Choice Parameter
- Fill in the fields:
| Field | Value |
|---|---|
| Name | env |
| Choices | See below |
| Description | (optional) Select the environment
|
For the Choices field, enter each option on its own line:
Development
Staging
Production
⚠️ Important: Do NOT use commas. Each choice must be on a separate line. Jenkins will parse them into a dropdown list. The order matters —
Developmentshould be first so it appears at the top.
What is a Choice Parameter?
It presents a dropdown of predefined options. Users pick one; no free-text input is allowed.
Final Parameter Order
Your configuration should show:
Parameters:
├── Stage (String) → default: "Build"
└── env (Choice) → Development | Staging | Production
Step 6: Configure the Shell Command
Scroll down to the Build section:
- Click Add build step → select Execute shell
- In the Command text area, enter:
echo "Stage: $Stage"
echo "Environment: $env"
How Parameter Injection Works
Jenkins exposes parameters as environment variables during the build. So $Stage and $env are available just like any shell variable. The syntax is case-sensitive — $env won't match $ENV or $Env.
Step 7: Save the Job
- Click Save at the bottom of the page
- You'll be redirected to the job page
The job page will now show a Build with Parameters option in the left sidebar (instead of just "Build Now").
Step 8: Build with Parameters
- Click Build with Parameters in the left sidebar
- You'll see a form:
-
Stage: text field pre-filled with
Build - env: dropdown with Development, Staging, Production
-
Stage: text field pre-filled with
- Select Development from the
envdropdown - Leave
StageasBuild(the default) - Click Build
Step 9: Verify the Build Output
In the left sidebar, Build History will show #1 appear. Click on #1 → Console Output.
You should see:
Started by user admin
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/parameterized-job
[parameterized-job] $ /bin/sh -xe /tmp/jenkins4687125526416196371.sh
+ echo Stage: Build
Stage: Build
+ echo Environment: Development
Environment: Development
Finished: SUCCESS
Reading the Output
| Line | Meaning |
|---|---|
+ echo Stage: Build |
Shell command Jenkins executed |
Stage: Build |
The string parameter value printed |
+ echo Environment: Development |
Second shell command |
Environment: Development |
The choice parameter value printed |
Finished: SUCCESS |
Build completed without errors |
The + prefix is the shell's trace mode (sh -x), which Jenkins enables by default to show every command it runs. It's incredibly useful for debugging.
Troubleshooting
| Issue | Solution |
|---|---|
| "Add Parameter" button missing | Make sure This project is parameterized is checked |
| Choice parameter only shows one option | Each choice must be on a separate line, not comma-separated |
$Stage prints empty |
Variable name must match exactly — Jenkins is case-sensitive |
| "Build with Parameters" not visible | Refresh the job page; ensure parameters were saved correctly |
| Build fails | Read the Console Output — the + lines show exactly what ran |
Summary
| # | Task | Result |
|---|---|---|
| 1 | Created parameterized-job
|
Freestyle project ✅ |
| 2 | Added String Parameter Stage
|
Default: Build ✅ |
| 3 | Added Choice Parameter env
|
Development / Staging / Production ✅ |
| 4 | Configured shell command | Echoed both values ✅ |
| 5 | Built with env = Development
|
Build #1 SUCCESS ✅ |
Key Takeaways
- Parameterized builds eliminate job duplication. One job, many configurations — perfect for multi-environment deployments.
- String vs. Choice has a clear purpose. Use String for free-text input with a sensible default; use Choice to constrain input to valid options.
-
Parameters become environment variables. Any script step can reference them via
$NAME. - Order matters in the UI. The order you add parameters is the order users see them in the "Build with Parameters" form.
-
The Console Output is your best friend. The
+lines reveal exactly what Jenkins executed — invaluable when debugging.
Real-World Applications
This simple pattern scales into serious CI/CD workflows:
-
Deploy to a specific environment: Choice parameter for
env, then use it in a deployment script -
Build a specific branch: String parameter for
BRANCH, thengit checkout $BRANCH -
Run with configurable versions: String parameter for
VERSION, thendocker build -t app:$VERSION -
Release channels: Choice parameter for
CHANNEL(stable/beta/nightly)
Once you're comfortable with parameters, the next step is chaining jobs together with the Parameterized Trigger plugin — but that's a topic for another blog.
Top comments (0)