Managing Job Import and Export
1. Exporting Job Configuration
| Property | Value | Description |
|---|---|---|
| job.name | my-job |
Name of the job to export |
| export.path | /var/lib/jenkins/jobs/my-job/config.xml |
Path where the configuration will be exported |
| format | xml |
Export format (XML is default) |
Example: Export job configuration via CLI
curl -X GET "http://jenkins.example.com/job/my-job/config.xml" -o /tmp/my-job-config.xml
Note: Ensure the Jenkins user has read permissions to the job configuration file.
2. Importing Job Configuration via CLI
| Command | Description | Options | Example |
|---|---|---|---|
| jenkins-cli | Command-line interface to manage Jenkins jobs | -s for server URL, -p for password, -i for job config file |
jenkins-cli -s http://localhost:8080 -p mypass -i job-config.xml |
Example: Importing a Job Configuration via CLI
jenkins-cli -s http://localhost:8080 -p mypassword -i /path/to/job-config.xml
Note: Ensure that the job configuration XML file is valid and compatible with the Jenkins version.
3. Using Job Import Plugin
| Property | Value | Description |
|---|---|---|
| plugin.id | job-import-plugin |
Unique identifier for the plugin |
| plugin.version | 1.5 |
Latest stable version as of 2026 |
| supported.format | XML |
Job configuration format supported by the plugin |
Example: Importing a Job Configuration
curl -X POST "http://jenkins.example.com/job/MyJob/import" \
-F "config.xml=@job-config.xml"
Note: The job configuration must be in valid Jenkins XML format.
Warning: Importing jobs may overwrite existing configurations.
| Option | Description | Default Value |
|---|---|---|
| import.mode | Import mode: merge or replace |
replace |
| preserve.permissions | Whether to preserve original permissions | false |
4. Migrating Jobs Between Instances
Migration Process Overview
- Export job configuration from source instance
- Transfer configuration files to target instance
- Import job configuration on target instance
- Verify job functionality post-migration
| Step | Description | Notes |
|---|---|---|
| Export via UI | Go to job > Configure > Export | Creates a ZIP archive containing config.xml and workspace files |
| Export via CLI | curl -X GET "http://source-jenkins/job/my-job/config.xml" |
Direct XML export for automation |
| Import via UI | Go to Manage Jenkins > New Item > Import | Supports ZIP or XML file uploads |
| Import via CLI | curl -X POST "http://target-jenkins/createItem?name=my-job" --data-binary @config.xml |
Requires Jenkins CLI or API access |
Example: Migrating a Job via CLI
curl -X GET "http://source-jenkins/job/my-job/config.xml" -o job-config.xml
curl -X POST "http://target-jenkins/createItem?name=my-job" --data-binary @job-config.xml
Note: Ensure Jenkins user has appropriate permissions for both source and target instances. Job dependencies (e.g., plugins, credentials) must also be migrated.
5. Using Configuration as Code for Jobs
| Property | Values | Description |
|---|---|---|
| jenkins.job.config | yaml |
Configuration as Code (JCasC) YAML format for defining jobs |
| job.name | string |
Name of the job to be created or updated |
| job.scm | string |
Source control management configuration (e.g., Git) |
| job.triggers | array |
List of triggers (e.g., SCMTrigger, TimerTrigger) |
| job.builders | array |
Build steps (e.g., shell, batch) |
| job.publishers | array |
Publishing actions (e.g., archiveArtifacts) |
Example: Basic Job Configuration in JCasC
jenkins:
jobs:
- name: "example-job"
scm:
git:
url: "https://github.com/example/repo.git"
branch: "main"
triggers:
- scmTrigger:
interval: "5m"
builders:
- shell: "echo 'Hello World'"
publishers:
- archiveArtifacts:
artifacts: "*.log"
Note: Configuration as Code (JCasC) allows declarative job definitions, making it easier to version control and manage Jenkins jobs in a CI/CD pipeline.
Warning: Ensure that sensitive data (e.g., credentials) in JCasC configurations are properly secured using Jenkins' credential store or external secret management tools.
6. Backing Up Job Definitions
Example: Using Jenkins CLI to export job configuration
jenkins-cli -s http://localhost:8080 get-job my-job > job-config.xml
| Command | Description | Notes |
|---|---|---|
| get-job | Exports job configuration as XML | Use with Jenkins CLI or API |
| copy-job | Creates a copy of an existing job | Can be used to backup before changes |
Note: Job configurations are stored as XML files in the
JENKINS_HOME/jobs/<job-name>/config.xml directory.Warning: Ensure
JENKINS_HOME is backed up regularly to prevent data loss.Backup Strategy
- Use Jenkins CLI or API to export job configurations
- Store XML files in version control (e.g., Git)
- Include
JENKINS_HOMEin regular backups
7. Cloning Jobs via API
| Property | Value | Description |
|---|---|---|
| Jenkins URL | http://localhost:8080 |
Base URL of the Jenkins instance |
| Job Name | example-job |
Name of the job to clone |
| New Job Name | cloned-example-job |
Name of the new cloned job |
Example: Clone Job via API
curl -X POST "http://localhost:8080/createItem?name=cloned-example-job" \
-H "Content-Type: text/xml" \
-d @job_config.xml
Note: The
job_config.xml file must contain the configuration of the original job.
Warning: Ensure that the user has sufficient permissions to create jobs in Jenkins.
8. Using Job DSL for Bulk Export
The Jenkins Job DSL plugin allows you to define jobs declaratively using Groovy scripts, enabling bulk export of job configurations.
| Property | Description | Example |
|---|---|---|
| jobName | Name of the job to be exported | "my-job" |
| script | DSL script defining job properties | |
Example: Exporting Jobs via DSL Script
import jenkins.model.Jenkins
import hudson.model.Job
def jobs = Jenkins.instance.getAllItems(Job.class)
jobs.each { job ->
println "Exporting job: ${job.name}"
// Export logic here
}
Note: The Job DSL plugin requires the
job-dsl plugin to be installed and configured in Jenkins.
Warning: Ensure that sensitive data (e.g., credentials) is not included in exported DSL scripts.
9. Managing Job Templates
| Property | Value | Description |
|---|---|---|
| template.name | "MyJobTemplate" |
Name of the job template |
| template.description | "Template for building Node.js projects" |
Description of the template |
| template.projectType | "freestyle" |
Project type (freestyle, pipeline, maven) |
| template.scm.type | "git" |
Source control management type |
| template.scm.url | "https://github.com/example/repo.git" |
Repository URL |
| template.buildSteps | ["npm install", "npm test"] |
List of build steps to execute |
Example: Creating a Job Template
jobTemplate('MyJobTemplate') {
description('Template for building Node.js projects')
projectType('freestyle')
scm {
git('https://github.com/example/repo.git')
}
buildSteps {
shell('npm install')
shell('npm test')
}
}
Note: Templates can be reused across multiple jobs to maintain consistency and reduce configuration overhead.
Warning: Changes to a job template will not automatically update existing jobs that use it.
10. Version Controlling Job Configurations
| Option | Values | Notes |
|---|---|---|
| job.config.path | jobs/<job-name>/config.xml |
Path where job configuration is stored in Jenkins home directory |
| scm.type | git, svn, mercurial |
Source control management system used for versioning job configs |
| job.config.backup | true, false |
Enables automatic backup of job configurations |
Example: Git Integration for Job Configs
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git branch: 'main', url: 'https://github.com/example/jenkins-jobs.git'
}
}
}
}
Note: Jenkins job configurations are stored as XML files and can be version controlled using Git or other SCM tools.
Warning: Manual edits to
config.xml files may cause inconsistencies if not synchronized with the Jenkins UI.
| Feature | Description | Status |
|---|---|---|
| Job Config Backup | Automated backup of job configurations to external storage | NEW |
| SCM Integration | Support for Git, SVN, and Mercurial to manage job config versions | DEPRECATED |