📖 Scenario: You are a Jenkins administrator setting up system configurations to manage build executors and environment variables for your team.
🎯 Goal: Learn how to create and update Jenkins system settings using the Jenkins Script Console with Groovy scripts.
📋 What You'll Learn
Create a Groovy script to set the number of executors
Add a system environment variable
Update the system configuration with these settings
Print the updated configuration values
💡 Why This Matters
🌍 Real World
Jenkins administrators often need to configure system-wide settings like executors and environment variables to optimize build performance and environment consistency.
💼 Career
Knowing how to script Jenkins system configuration helps DevOps engineers automate setup and maintenance tasks, improving CI/CD pipeline reliability.
Progress0 / 4 steps
1
Create initial Jenkins system configuration variables
Create a variable called jenkins that gets the Jenkins instance using Jenkins.get(). Then create a variable called currentExecutors that stores the current number of executors using jenkins.getNumExecutors().
Jenkins
Hint
Use Jenkins.get() to get the Jenkins instance and getNumExecutors() to get the number of executors.
2
Add a new system environment variable
Create a variable called envVars that gets the system environment variables using jenkins.getGlobalNodeProperties(). Then add a new environment variable with name DEPLOY_ENV and value production using hudson.slaves.EnvironmentVariablesNodeProperty.Entry and add it to envVars.
Jenkins
Hint
Look for existing environment variables in global node properties. If none, create a new EnvironmentVariablesNodeProperty. Then add the new entry.
3
Update the number of executors in Jenkins system settings
Set the number of executors to 5 using jenkins.setNumExecutors(5). Then save the Jenkins configuration using jenkins.save().
Jenkins
Hint
Use setNumExecutors(5) to update executors and save() to apply changes.
4
Print the updated Jenkins configuration values
Print the updated number of executors using print(jenkins.getNumExecutors()). Then print the value of the environment variable DEPLOY_ENV from envVars.getEnvVars() using print(envVars.getEnvVars().get('DEPLOY_ENV')).
Jenkins
Hint
Use print() to show the updated executors and environment variable.
Practice
(1/5)
1. What is the main purpose of the Configure System page in Jenkins?
easy
A. To view build logs of completed jobs
B. To create new Jenkins jobs
C. To install Jenkins plugins
D. To set global settings that affect all Jenkins jobs and nodes
Solution
Step 1: Understand Jenkins system configuration
The Configure System page is used to set global settings that apply to the entire Jenkins instance.
Step 2: Differentiate from other Jenkins pages
Creating jobs, viewing logs, and installing plugins are done in other sections, not in Configure System.
Final Answer:
To set global settings that affect all Jenkins jobs and nodes -> Option D
Quick Check:
Configure System = Global settings [OK]
Hint: Configure System sets global Jenkins settings [OK]
Common Mistakes:
Confusing Configure System with job creation
Thinking Configure System manages plugins
Mixing build logs with system settings
2. Which of the following is the correct way to access the Jenkins system configuration page?
easy
A. Go to Manage Jenkins > Configure System
B. Go to Dashboard > New Item
C. Go to Manage Jenkins > Plugin Manager
D. Go to Build History > Configure
Solution
Step 1: Identify the navigation path for system settings
The system configuration page is accessed via Manage Jenkins then Configure System.
Step 2: Eliminate incorrect navigation options
New Item is for creating jobs, Plugin Manager is for plugins, and Build History does not have configuration options.
Final Answer:
Go to Manage Jenkins > Configure System -> Option A
Quick Check:
Manage Jenkins > Configure System = Correct path [OK]
Hint: System config is under Manage Jenkins > Configure System [OK]
Common Mistakes:
Selecting Plugin Manager instead of Configure System
Confusing New Item with system settings
Looking for configuration in Build History
3. After setting an environment variable in Jenkins' Configure System page, what will happen when a job runs?
medium
A. The job will have access to the environment variable during its execution
B. The environment variable will only apply to the Jenkins master node
C. The environment variable will be ignored unless set in the job itself
D. The environment variable will cause the job to fail if not declared in the job config
Solution
Step 1: Understand environment variables in Configure System
Setting environment variables globally makes them available to all jobs during execution.
Step 2: Clarify scope and effect
These variables are injected into the job's environment, so the job can use them without declaring them again.
Final Answer:
The job will have access to the environment variable during its execution -> Option A
Quick Check:
Global env vars = Available in jobs [OK]
Hint: Global env vars set in Configure System apply to all jobs [OK]
Common Mistakes:
Thinking env vars only apply to master node
Assuming jobs must declare env vars again
Believing env vars cause job failure if undeclared
4. You configured a tool path in Jenkins' Configure System, but jobs fail saying the tool is not found. What is the most likely cause?
medium
A. The job configuration overrides the global tool path
B. The tool must be installed via Jenkins Plugin Manager
C. The tool path is incorrect or not accessible by Jenkins
D. Jenkins requires a restart after setting tool paths
Solution
Step 1: Check tool path correctness
If Jenkins cannot find the tool, the path set in Configure System is likely wrong or Jenkins lacks permission to access it.
Step 2: Understand plugin and restart roles
Tools usually do not require plugins to be installed, and Jenkins does not always need a restart for path changes.
Final Answer:
The tool path is incorrect or not accessible by Jenkins -> Option C
Quick Check:
Incorrect tool path = Job failure [OK]
Hint: Verify tool path and permissions if jobs fail to find tools [OK]