我正在尝试使用jenkins rest api。说明书上说我需要有api密钥。我已经找遍了所有的配置页面来找到它。如何获取jenkins的API密钥?
发布于 2017-08-03 00:24:43
从Jenkins 2.129开始,API令牌配置has changed
现在,您可以拥有多个令牌并对其进行命名。它们可以单独撤销。
Jenkins 2.129之前:显示API token,如下所示:
显示您的姓名(右上角为corner).
将显示API令牌。
您可以通过单击Change API Token按钮来更改token。
发布于 2019-03-26 10:30:30
在Jenkins 2.129之后,非UI的方法是:
curl 'https://<jenkinsURL>/me/descriptorByName/jenkins.security.ApiTokenProperty/generateNewToken' \
--data 'newTokenName=foo' \
--user username:Password它返回:
{
"status": "ok",
"data": {
"tokenName": "foo",
"tokenUuid": "<uuid>",
"tokenValue": "<redacted>"
}
}Jenkins 2.129之前的版本
curl http://<username>:<password>@<jenkins-url>/me/configure 发布于 2020-10-11 03:51:27
在Jenkins 2.225中测试的
经过几个小时的研究,我找到了答案:
使用Api令牌代替CSFR令牌。但是,如果您想要从任何其他客户端(POSTMAN、CLI。卷曲等)。
首先,您需要获取CSFR令牌,并使用--cookie-jar将信息保存在cookie中
curl -s --cookie-jar /tmp/cookies -u用户名:密码http://localhost:8080/crumbIssuer/api/json
Crumb{ "crumb":"_class":"bc92944100d12780cfc251c9255f3f323a475562b4ee0d8b9cc6e4121f50a450","crumbRequestField":“Jenkins-crumbRequestField”}
然后,我们可以使用--cookie读取cookie并生成新的令牌:
cookie curl -X POST cookie 'Jenkins-Crumb:your_crumb_token_generated_above‘--cookie /tmp/cookies http://localhost:8080/me/descriptorByName/jenkins.security.ApiTokenProperty/generateNewToken?newTokenName=\your_token_name -u用户名:密码
{ "status":"ok","data":{ "tokenName":“我的android token","tokenUuid":"c510e26c-b2e8-4021-bf79-81d1e4c112af","tokenValue":"11a2a0c91913d1391d8e8cb155ca714581”} }
https://stackoverflow.com/questions/45466090
复制相似问题