關於得到/檢測Jenkins的Version,下面頁面(Jenkins Remote access API)中有說明:java
https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+APIpython
Detecting Jenkins version(檢測Jenkins的Version)git
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. github
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.api
使用的瀏覽器爲Chrome,在Chrome中查看response header方法以下:瀏覽器
一、按F12,彈出對話框,按Network選項;post
二、點擊網址/jenkins/api/python,而後點擊Header/Response Headers就能夠了。url
使用Python獲取Jenkins Version的example以下:code
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')
運行結果以下:ci
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); }