/**
*
* 方法简介.获取Job日志
*
* @author HSG
* @throws Exception
* @date 创建时间 2020年10月22日
* @since V1.0
*/
public static String getConsoleOutLog(JenkinsServer jenkinsServer, String jobName) throws Exception{
JobWithDetails jobWithDetails = jenkinsServer.getJob(jobName).details();
int nextNum = jobWithDetails.getNextBuildNumber();//最新的一次构建索引
Build buildByNumber = jobWithDetails.getBuildByNumber(nextNum);
Boolean isBuilding = true;
while (isBuilding) {
if (null == buildByNumber) {
jobWithDetails = jenkinsServer.getJob(jobName).details();
buildByNumber = jobWithDetails.getBuildByNumber(nextNum);
}
if (null != buildByNumber) {
BuildWithDetails details = buildByNumber.details();
if (null != details) {
isBuilding = details.isBuilding();
} else {
isBuilding = true;
}
} else {
isBuilding = true;
}
}
BuildResult buildResult = jobWithDetails.getLastBuild().details().getResult();
ConsoleLog consoleLog = jobWithDetails.getLastBuild().details().getConsoleOutputText(0);
String consoleTxt = consoleLog.getConsoleLog();
return consoleTxt;
}