问题描述
我有一个通过 curl HTTP 调用删除和重新创建作业的脚本,我想摆脱任何硬编码的用户名:密码".例如.curl -X POST $url --user 用户名:密码
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
注意事项:
Jenkins CLI(可能不是一个选项).使用 CLI 应该能够实现与使用 Jenkins API(创建作业等)相同的效果,但据我所知,Jenkins CLI 对我来说不是一个好的选择,因为使用创建的作业只会在重新启动或重新加载"后出现在 Jenkins 中从磁盘配置",这将取消任何其他正在运行的作业.
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 令牌.无法找到如何获取用户令牌然后传递它作为脚本的参数,但这可能是一个解决方案..
API token. Can't find out how to get the user token and then pass itas a parameter to the script, but that may be a solution..
推荐答案
试试这个:(比如删除作业)
Try this way: (for example delete the job)
curl --silent --show-error http://<username>:<api-token>@<jenkins-server>/job/<job-name>/doDelete
api-token可以从http:///user//configure
获取.
The api-token can be obtained from http://<jenkins-server>/user/<username>/configure
.
这篇关于Jenkins 用户身份验证详细信息如何“通过"?到使用 Jenkins API 创建作业的脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!