How to move a job remotely

Issue

How to move a job remotely.

Environment

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

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"

The above copies job example-job to a new job named moved-example-job.

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.

Have more questions?

0 Comments

Please sign in to leave a comment.