Logo Valérian de Thézan de Gaussan

How to safely bulk-edit Jenkins job configurations with sed

Valerian Valerian
July 10, 2025
3 min read
Table of Contents

Managing Jenkins often means you need to update configuration values in many job files at once.
If you want to change a value, such as a build label, across dozens or hundreds of jobs, doing it manually is error-prone and slow.

This guide explains how to bulk-edit these values safely using sed, with proper backup and rollback steps.

I found myself in such a situation today with a client’s Jenkins. Many (many!) job needed updates, and I couldn’t accept hours of clicking through job configurations one by one. I knew there had to be a better way, but surprisingly, clear guidance seemed elusive in the vast expanse of the internet.

So, I found an easy way of doing it. Now, I want to share this knowledge to help others avoid the same struggles.


Problem Statement

Suppose all your jobs use the build label legacy-linux, and you want to upgrade to ubuntu-22-04.
Each job’s configuration file is at jobs/<job-name>/config.xml and contains a line like:

<label>legacy-linux</label>

You want to update all occurrences to:

<label>ubuntu-22-04</label>

1. Back up all config.xml files

Before making any changes, back up every config.xml file.
This allows you to roll back if something goes wrong.

Backup command (preserves directory structure):

cd /var/jenkins_home/jobs
find . -name config.xml | tar -czvf /tmp/config_xml_backup_$(date +%Y%m%d%H%M%S).tar.gz -T -
  • This archives all config.xml files with their folder structure. Preserving the structure will allow us later to roll back all the jobs without effort (see Section 5).

2. Stop Jenkins safely

Always stop Jenkins before editing configs to avoid file corruption.

For Docker-based Jenkins:

docker stop <jenkins_container>

Or use a safe shutdown with Jenkins CLI if you have it.


3. Run the sed replacement

Now perform the replacement across all configs:

find /var/jenkins_home/jobs -name config.xml -exec sed -i 's#<label>legacy-linux</label>#<label>ubuntu-22-04</label>#g' {} +
  • This command replaces every instance of <label>legacy-linux</label> with <label>ubuntu-22-04</label> in place.

4. Start Jenkins and validate

Restart Jenkins:

docker start <jenkins_container>
  • Open the Jenkins UI and check a few jobs to ensure labels updated as expected.
  • Watch logs for any errors.

5. Roll back if needed

If anything broke, restore the original configs from your backup:

cd /var/jenkins_home/jobs
tar -xzvf /tmp/config_xml_backup_<timestamp>.tar.gz
  • This will restore all config.xml files to their pre-change state.

Key points

  • Never edit job configs while Jenkins is running.
  • Always make a backup first.
  • Think before doing the sed, you might break the XML stucture! For complex changes, use XML tools.
  • Test your change on a single job before running on all jobs.

This approach gives you a safe, repeatable way to automate Jenkins configuration changes.