How to move a job remotely

Article ID:360035625171
2 minute readKnowledge base

Issue

How to move a job remotely.

Resolution

If using CJOC

If your controller is connected to a CJOC instance, then the simplest solution might be to use the Move / Copy / Promote functionality provided by CJOC.

See Moving, Copying, or Promoting Items Using the Jenkins CLI for how to execute these operations remotely.

NOTE:: This approach allows you the option to also move build history.

If not using CJOC

There doesn’t appear to be a move operation, so the simplest solution might be to use a combination of copy and then delete operations to simulate a move operation.

NOTE: This approach will move the job config only. It does not move build history or build artifacts.

Example (using cURL)

The root URL for this instance is https://localhost:8080.

The admin username and API token for this instance is admin:token.

1) Copy job
  • Example that copies job example-job to a new job named moved-example-job on the same controller location.

    curl -s -XPOST 'https://localhost:8080/createItem?name=moved-example-job&mode=copy&from=example-job' -u admin:token -H "$CRUMB" -H "Content-Type:text/xml"
  • Example that copies job example-job from folder folder to a new job named moved-example-job on the folder2 folder.

    curl -s -XPOST 'https://localhost:8080/job/folder2/createItem?name=moved-example-job&mode=copy&from=folder/example-job' -u admin:token -H "$CRUMB" -H "Content-Type:text/xml"
Jobs created though the REST API are subjected to migration by the RunIdMigrator on the next Jenkins startup. Please have a look at Jenkins Startup logs show RunIdMigrator logs.
2) Delete old job
curl -X POST https://localhost:8080/job/example-job/doDelete -u admin:token -H "$CRUMB"

The above example deletes the job example-job.