Issue
How to move a job remotely.
Environment
- CloudBees CI (CloudBees Core)
- CloudBees CI (CloudBees Core) on modern cloud platforms - Managed Master
- CloudBees CI (CloudBees Core) on modern cloud platforms - Operations Center
- CloudBees CI (CloudBees Core) on traditional platforms - Client Master
- CloudBees CI (CloudBees Core) on traditional platforms - Operations Center
- CloudBees Jenkins Enterprise
- CloudBees Jenkins Enterprise - Managed Master
- CloudBees Jenkins Enterprise - Operations Center
- CloudBees Jenkins Platform - Client Master
- CloudBees Jenkins Platform - Operations Center
- CloudBees Jenkins Distribution
- Jenkins LTS
Resolution
If using CJOC
If your master 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 http://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 namedmoved-example-job
on the same Master location.
curl -s -XPOST 'http://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 folderfolder
to a new job namedmoved-example-job
on thefolder2
folder.
curl -s -XPOST 'http://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"
Note: 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 http://localhost:8080/job/example-job/doDelete -u admin:token -H "$CRUMB"
The above example deletes the job example-job
.
0 Comments