Sourafa
Sourafa

Reputation: 255

generate jenkins api token using rest api

Hello I am using Jenkins API using Basic Auth of ldap. Now, i figured out that the API can be accessed through tokens as well. However these tokens are specific to each jenkins instance, I want to know if there is a way to retrieve these API tokens using REST api calls?

Upvotes: 0

Views: 5258

Answers (1)

luka5z
luka5z

Reputation: 7805

Although this information is not directly available through REST API or jenkins-cli, API token could be still extracted using Basic authentication when making a HTTP request.

An example based on curl and bash tools:

curl --silent --basic http://<username>:<password>@<jenkins-url>/me/configure | hxselect '#apiToken' | sed 's/.*value="\([^"]*\)".*/\1\n/g'

ps. HTML output is parsed using hxselect from html-xml-utils and sed.

Upvotes: 1

Related Questions