通过Jenkins API获得/检测Jenkins的Version

本文介绍了如何检测Jenkins版本的方法,包括使用浏览器查看响应头和Python脚本获取版本号。适用于Chrome浏览器,并提供了Python示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

关于获得/检测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就可以了。

145507_k3eo_1588291.png


使用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);
}


转载于:https://my.oschina.net/donhui/blog/468382

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值