backup policies on my network imply giving a path to backup and an optional command to run just before, so that I can prepare the backup
I need to backup my Jenkins configuration. Simply giving a path to the Jenkins data directory is not an option as:
I installed the Backup Plugin and found reasonably good settings for it. Now I wonder if I can trigger it remotely using a bash script. I understand that using curl
on the /jenkins/backup/launchBackup url should do the trick, but I'm getting a 403 Forbidden error as I'm hitting the URI as an anonymous user, and couldn't find a solution to login or get around this.
So does anyone knows of a simple way to trigger a configuration only backup from the command line ?
The Jenkins wiki describes how to perform an authenticated login in scripts. Short answer: Go to the Configure screen from your user page and get the API token, then use it as your password when running your script.
I haven't tried it with the Backup plugin, but it works for running regular builds so it should work for any scriptable invocation.
Without authentication:
$ curl http://jenkins:8080/job/my%20job/build
[ HTML page saying "Authentication required" ]
With authentication:
$ curl --user dbacher:$MY_API_TOKEN http://jenkins:8080/job/my%20job/build
[ returns nothing and the build starts ]
Update: fixed the jobs typo, thanks for the comments.
Dave Bacher's answer didn't work for me. I needed to do:
$ curl http://jenkins:8080/job/MY_JOB_NAME/build?build
It's job, not jobs, and I needed the ?build on the end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With