问题描述
如何使用Jenkins REST API获取作业的详细信息以及控制台输出
How to get the details of the job along with it console output using Jenkins REST API
构建示例
控制台输出:
我正在使用以下命令来获取控制台日志的路径
I am using following commands to get the path of console log
回显$ JENKINS_HOME/jobs/$ JOB_NAME/builds/$ {BUILD_NUMBER}/log
echo $JENKINS_HOME/jobs/$JOB_NAME/builds/${BUILD_NUMBER}/log
回显$ BUILD_URL/consoleText
echo $BUILD_URL/consoleText
它将提供控制台日志的路径
It would provide the path to console log
http://localhost:8080/job/Echo/25//consoleText
但是,如果我尝试使用c#.net从数据中获取数据,则会通过我发生异常
but if i try to get the data from it using c#.net it would through me a exception
我正在使用以下代码来获取数据
I am using following code to get the data
public string Download_Contents(string URI)
{
string Data = string.Empty;
try
{
using (var wc = new System.Net.WebClient())
Data = wc.DownloadString(URI);
}
catch (Exception ex)
{
throw ex;
}
return Data;
}
例外:
推荐答案
因此,使用consoleFull
时,使用curl
示例:
curl -s -S -u "user":"password" "http://jenkins.domain.com/job/my_job_name/1077/consoleFull"
输出:用html内容包裹的许多行:
output:many lines wrapped with html stuff:
<span class="timestamp"><b>09:04:32</b> </span><span style="color: #00CD00;">ok:</span>
所以我的解决方案是使用:
so my solution is to use:
curl -s -S -u "user":"password" "http://jenkins.domain.com/job/my_job_name/1077/logText/progressiveText?start=0"
,您将获得相同的控制台日志输出,而没有html,span的东西
and you will get the same console log output without the html,span stuff
这篇关于Jenkins REST API获取作业和作业控制台日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!