Skip to main content
In this tutorial, you’ll learn how to fetch, modify, and update a Freestyle job (npm-version-test) on Jenkins using the Jenkins CLI. The job prints the installed Node.js and npm versions. We’ll download its XML configuration, adjust the build steps, and push the changes back.

Prerequisites

  • Jenkins server accessible at http://localhost:8080/
  • jenkins-cli.jar downloaded locally
  • CLI access via SSH; for example:

1. Check Installed Node.js & npm

First, verify your local Node.js and npm versions:

2. Download the Job Configuration

Fetch the existing job’s XML to a local file.

2.1 Using HTTP

2.2 Using SSH

Always back up your existing XML before editing. You can keep a copy:

3. Inspect the Current Configuration

Open npm-job.xml and locate the <builders> section. It should resemble:

4. Update the Build Steps

Modify npm-job.xml so the shell step echoes a message and invokes both Node.js and npm versions. Replace the <builders> section with:
Save your edits to npm-job.xml.

5. Push the Updated Configuration

Send the modified XML back to Jenkins:

5.1 Via SSH

5.2 Via HTTP

A successful update returns no output.

6. Verify Your Changes

  1. In the Jenkins UI, open npm-version-test.
  2. Check that the build step now shows:
  3. Trigger a new build. The console log should display something like:
That’s it! You’ve successfully edited a Freestyle job’s configuration and updated it in Jenkins using the CLI.

Watch Video