retrieve jenkins console output
@Api(value = "console", description = "Retrieve the Console Outputs",produces=MediaType.APPLICATION_JSON_VALUE)
@Controller
public class ConsoleController {
@RequestMapping(value = "/consoleLogs/{job}", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Getting jenkins console outputs", notes = "Getting jenkins console outputs")
@ResponseBody public String getConsoleOutputs(@ApiParam(value="url",required=true)@PathVariable(value = "job") String job)
throws Exception {
StringBuilder result = new StringBuilder();
URL url = new URL("http://localhost:8080/job/"+job+"/lastBuild/logText/progressiveText?start=0");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(30000);
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
result.append(line);
}
rd.close();
return result.toString();
}
}