在远程访问其JSON API时如何在Jenkins中进行身份验证? [英] How to authenticate in Jenkins while remotely accessing its JSON API?

查看:268
本文介绍了在远程访问其JSON API时如何在Jenkins中进行身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从Python脚本访问Jenkins JSON API.问题在于我们的Jenkins安装是安全的,因此登录用户必须选择一个证书.遗憾的是,在Jenkins 远程访问文档中,他们没有提到关于证书的事情,我尝试使用API​​令牌没有成功.

I need to access the Jenkins JSON API from a Python script. The problem is that our Jenkins installation is secured so to log in users have to select a certificate. Sadly, in Jenkins Remote Access Documentation they don't mention a thing about certificates and I tried using the API Token without success.

如何从Python脚本进行身份验证以使用其JSON API?

How can I get to authenticate from a Python script to use their JSON API?

提前谢谢!

推荐答案

您必须使用HTTP基本身份验证向JSON API进行身份验证.

You have to authenticate to the JSON API using HTTP Basic Auth.

要使脚本客户端(例如wget)调用需要授权的操作(例如计划构建),请使用HTTP BASIC身份验证指定用户名和API令牌.通常比模拟基于表单的身份验证更方便

To make scripted clients (such as wget) invoke operations that require authorization (such as scheduling a build), use HTTP BASIC authentication to specify the user name and the API token. This is often more convenient than emulating the form-based authentication

https://wiki.jenkins-ci.org/display/JENKINS/Authenticating + scripted +客户

这里是将Basic Auth与Python结合使用的示例.

Here is a sample of using Basic Auth with Python.

http://docs.python-requests.org/en/master /user/authentication/

请记住,如果您在内部Jenkin服务器上使用自签名证书,则需要关闭证书验证 OR ,从服务器获取证书并将其添加到HTTP请求中

Keep in mind if you are using a Self Signed certificate on an internal Jenkin Server you'll need to turn off certificate validation OR get the certificate from the server and add it to the HTTP request

http://docs.python-requests.org/en/master /user/advanced/

这篇关于在远程访问其JSON API时如何在Jenkins中进行身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆