Starting a Jenkins backup from the command line using the Backup plugin

Problem

backup policies on my network include providing a backup path and an optional command to run just before I can prepare a backup

I need to backup my Jenkins configuration. Just specifying the Jenkins data directory path is not a parameter:

  • I just need to backup the configuration
  • the total disk usage for this directory, ~ 80 GB, far exceeds the reasonable backup size (99% consists of non-critical workspace data).

Until

I installed Backup Plugin and found quite good settings for it. Now I am wondering if I can run it remotely using a bash script. I understand that using curl in the URL / jenkins / backup / launchBackup should do the trick, but I get Forbidden error 403 as I press the URI as an anonymous user and cannot find a solution for logging in or getting around this.

Does anyone know of a simple way to run a configuration from a command line backup only?

+4
source share
2 answers

The Jenkins wiki describes how to authenticate with scripts . The short answer. Go to the “Settings” screen from your user page and get the API token, and then use it as a password when running the script.

I have not tried it with the Backup plugin, but it works to run regular collections, so it should work for any script call.

No Authentication:

 $ curl http://jenkins:8080/job/my%20job/build [ HTML page saying "Authentication required" ] 

Authenticated:

 $ curl --user dbacher:$MY_API_TOKEN http://jenkins:8080/job/my%20job/build [ returns nothing and the build starts ] 

Update : misspelled missions, thanks for the comments.

+9
source

Dave Bacher’s answer didn’t work for me. I needed to do:

 $ curl http://jenkins:8080/job/MY_JOB_NAME/build?build 

This is work, not a task, and I had to build in the end.

+2
source

Source: https://habr.com/ru/post/1446468/


All Articles