关于获得/检测Jenkins的Version,下面页面(Jenkins Remote access API)中有说明:
https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API
Detecting Jenkins version(检测Jenkins的Version)
To check the version of Jenkins, load the top page (or, as of 1.483, any .../api/* page too) and check for the X-Jenkins response header.
This contains the version number of Jenkins, like "1.404" This is also a good way to check if an URL is a Jenkins URL.
使用的浏览器为Chrome,在Chrome中查看response header方法如下:
1、按F12,弹出对话框,按Network选项;
2、点击网址/jenkins/api/python,然后点击Header/Response Headers就可以了。
使用Python获取Jenkins Version的example如下:
import requests jenkins_python_api_url = "http://localhost:8080/jenkins/api/python" response = requests.post(jenkins_python_api_url) print response.headers.get(‘x-jenkins‘)
运行结果如下:
1.592
注意:获取Jenkins的Version无需考虑认证情况(无论是否需要认证,都可以获得Jenkins的Version)
同时,通过查阅Jenkins的相关源码,可以得知ResponseHeader消息头中存储的"X-Jenkins"即为Jenkins.VERSION:
private void setHeaders(StaplerResponse rsp) { rsp.setHeader("X-Jenkins", Jenkins.VERSION); rsp.setHeader("X-Jenkins-Session", Jenkins.SESSION_HASH); }
时间: 2024-10-03 20:46:23