How can a Jenkins user authentication details be "passed" to a script which uses Jenkins API to create jobs?

HenrikSN picture HenrikSN · May 22, 2012 · Viewed 119.8k times · Source

I have a script that delete and re-create jobs through curl HTTP-calls and I want to get rid of any hard-coded "username:password". E.g. curl -X POST $url --user username:password

Considerations:

  • Jenkins CLI (probably not an option). One should be able to achieve the same with the CLI as with Jenkins API (creating jobs etc) but as far as I understand Jenkins CLI is not a good alternative for me since jobs created with will only appear in Jenkins after restarting or a "Reload Configuration from Disk", and that would cancel any other running jobs.

  • API token. Can't find out how to get the user token and then pass it as a parameter to the script, but that may be a solution..

Answer

PiotrO picture PiotrO · Feb 13, 2013

Try this way: (for example delete the job)

curl --silent --show-error http://<username>:<api-token>@<jenkins-server>/job/<job-name>/doDelete

The api-token can be obtained from http://<jenkins-server>/user/<username>/configure.