Managing Global Configuration
1. Configuring System Settings
| Setting | Description | Default Value | Notes |
|---|---|---|---|
| System Admin Email | Admin email address for system notifications | None | Required for email notifications |
| Global Tool Configuration | Define global tools like JDK, Maven, etc. | None | Used by jobs to access tools |
| Global Security | Configure security settings for the entire Jenkins instance | None | Includes authentication and authorization settings |
| Global Environment Variables | Environment variables available to all jobs | None | Can be overridden per job |
Example: Setting Global Environment Variables
environment {
JAVA_HOME = "/usr/lib/jvm/java-11-openjdk"
MAVEN_HOME = "/opt/maven"
}
Note: Changes to global settings may require a Jenkins restart to take effect.
2. Setting Global Properties
| Property | Value | Description |
|---|---|---|
| JENKINS_URL | http://localhost:8080 |
Base URL for Jenkins instance |
| JAVA_HOME | /usr/lib/jvm/java-11-openjdk |
Path to Java installation |
| JENKINS_HOME | /var/lib/jenkins |
Directory where Jenkins stores data |
Example: Setting Global Properties via CLI
java -Djenkins.url=http://localhost:8080 -jar jenkins.war
Note: Global properties can also be set through the Jenkins web UI under
Manage Jenkins > Configure System.
3. Configuring JDK Installations
| Property | Value | Description |
|---|---|---|
| JDK Name | jdk-11 |
Name used to identify the JDK installation in Jenkins configuration |
| Java Home | /usr/lib/jvm/java-11-openjdk |
Path to the JDK installation directory |
4. Configuring Maven Installations
| Property | Value | Description |
|---|---|---|
| maven.home | /opt/maven |
Path to the Maven installation directory |
| maven.version | 3.9.6 |
Version of Maven to use |
Example: Setting up Maven in Jenkins
pipeline {
agent any
tools {
maven 'apache-maven-3.9.6'
}
stages {
stage('Build') {
steps {
sh 'mvn clean compile'
}
}
}
}
Note: Ensure that the Maven installation is correctly configured in Jenkins global tool configuration before using it in pipelines.
5. Configuring Git Installations
| Property | Values | Description |
|---|---|---|
| git.installation.path | /usr/bin/git |
Path to the Git executable on the system |
| git.installation.name | Default Git |
Name identifier for the Git installation |
Example: Git Installation Configuration
import hudson.plugins.git.GitTool
import hudson.tools.InstallableTool
import jenkins.model.Jenkins
def gitTool = new GitTool(
name: "Custom Git",
home: "/usr/local/bin/git"
)
Jenkins.instance.getDescriptor(GitTool).setInstallations([gitTool])
Jenkins.instance.save()
Note: Ensure the Git executable path is accessible from Jenkins' execution environment.
6. Setting Usage Statistics Preferences
Example: Configure Usage Statistics
import jenkins.model.Jenkins
def jenkins = Jenkins.getInstance()
def usageStats = jenkins.getUsageStatistics()
// Enable sending usage statistics
usageStats.setCollectUsageStats(true)
// Save the configuration
jenkins.save()
| Property | Values | Description |
|---|---|---|
| collectUsageStats | true / false |
Controls whether Jenkins collects and sends usage statistics to the Jenkins project. |
| lastSentDate | ISO 8601 date string |
Date when the last statistics were sent. |
Note: Usage statistics are sent once per day, and can be disabled at any time via the UI or API.
7. Configuring Email Notification
| Property | Value | Description |
|---|---|---|
| hudson.model.Jenkins.adminAddress | jenkins@example.com |
Admin email address for system notifications |
| hudson.plugins.email.ExtendedEmailPublisher.defaultRecipients | team@example.com |
Default recipients for email notifications |
| hudson.plugins.email.ExtendedEmailPublisher.defaultSubject | Build ${BUILD_NUMBER} ${BUILD_STATUS} |
Default subject line for emails |
Example: Configure Email Settings via Jenkins UI
Manage Jenkins > Configure System > E-mail Notification
Example: Using Jenkinsfile for Email Configuration
pipeline {
agent any
post {
always {
emailext (
subject: "Build ${BUILD_NUMBER} ${BUILD_STATUS}",
to: "team@example.com",
body: "Build details available at ${BUILD_URL}"
)
}
}
}
Note: Ensure SMTP settings are configured under
Manage Jenkins > Configure System for email delivery to work properly.
8. Setting Build Record Retention
| Property | Values | Description |
|---|---|---|
| buildsToKeep | 0 |
Number of builds to keep. 0 means unlimited. |
| daysToKeep | 0 |
Number of days to keep builds. 0 means unlimited. |
| artifactDaysToKeep | -1 |
Number of days to keep artifacts. -1 means use daysToKeep. |
| artifactNumToKeep | -1 |
Number of artifacts to keep. -1 means use buildsToKeep. |
Example: Configure retention in Jenkinsfile
pipeline {
agent any
options {
buildDiscarder logRotator(daysToKeep: 7, numToKeep: 5)
}
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
}
Note: The
logRotator option is part of the pipeline directive and applies to all builds in that pipeline.
9. Configuring Workspace Cleanup Policies
| Policy | Description | Configuration | Notes |
|---|---|---|---|
| Log Rotation | Automatically deletes old build logs to save space | buildsToKeep: Number of builds to keepdaysToKeep: Days to keep logs |
Default: 10 builds, 7 days |
| Workspace Cleanup | Deletes workspace directories after builds | cleanAfterSuccessfulBuild: BooleancleanAfterFailedBuild: Boolean |
Can be configured per job or globally |
| Artifacts Retention | Manages retention of build artifacts | artifactArchivingDisabled: BooleanmaxBuildsToKeep: Number of builds to archive |
Artifacts are stored in $JENKINS_HOME/artifacts |
Example: Global Workspace Cleanup Configuration
// Groovy script to configure global workspace cleanup
import jenkins.model.Jenkins
def jenkins = Jenkins.instance
jenkins.setBuildsToKeep(5)
jenkins.setDaysToKeep(3)
jenkins.setArtifactArchivingDisabled(false)
jenkins.setMaxBuildsToKeep(10)
// Save configuration
jenkins.save()
Note: Workspace cleanup policies can be overridden at the job level using the
Build Environment section in job configuration.
Warning: Disabling workspace cleanup can lead to disk space exhaustion over time.
10. Setting Global Pipeline Libraries
| Property | Value | Description |
|---|---|---|
| name | my-library |
Name of the library to be referenced in pipelines |
| retrievalMethod | modernSCM |
Method used to retrieve the library (e.g., modernSCM, legacy) |
| scm | {url: 'https://github.com/example/my-library.git'} |
Source control management configuration for the library |
| defaultVersion | master |
Default branch or tag to use if not specified in pipeline |
| implicit | false |
Whether the library is automatically available to all pipelines |
| allowOverride | true |
Allows individual pipelines to override the library version |
Example: Global Library Configuration
library(
name: 'my-library',
version: 'v1.0',
implicit: false,
allowOverride: true
)
Note: Libraries must be defined in the Jenkins Global Configuration under
Manage Jenkins > Configure System.
Warning: Ensure the library repository is accessible to Jenkins and has proper credentials configured if required.