0
0
Jenkinsdevops~30 mins

Configuring system settings in Jenkins - Try It Yourself

Choose your learning style9 modes available
Configuring system settings
📖 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
Need a 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
Need a 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
Need a 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
Need a hint?

Use print() to show the updated executors and environment variable.