触发并读取Jenkins控制台日志

huangapple go评论88阅读模式
英文:

Trigger and read jenkin console logs

问题

我计划自动触发Jenkins任务并读取控制台日志以进行验证。
目前,我能够使用Java触发Jenkins构建。
有没有一种方法可以使用Java读取控制台日志?

哪种其他语言将有助于执行相同的任务?

英文:

I am planning to automate triggering jenkins job and read console logs to validate.
Currently I am able to trigger jenkins build using java.
Is there a way to read console logs using java?

Which other language will be useful to perform the same task?

答案1

得分: 1

你可以通过向日志URL发送简单的GET请求来获取任何作业的日志。例如,如果你有一个名为test的作业,想要获取构建5的日志,使用以下方式:

http://<主机>:<端口>/job/test/5/consoleText

你可以像调用任何常规终端点一样,使用Java(或任何其他语言)调用此URL,并以纯文本形式获取日志。

**编辑:**一旦作业被触发,该构建将是该作业中已运行的最后一个构建。因此,你可以通过调用以下方式来获取构建编号:

http://<主机>:<端口>/job/test/lastBuild/buildNumber

以与调用任何其他终端点的方式相同。即使在同一作业上触发多个构建,也可以确保从上述URL获取构建编号,并在每次触发新作业时将其保存在数组中。

英文:

You can get the logs for any job by sending a simple GET request to the log url. For example, if you had a job called test and you wanted to get the logs of build 5, use:

http://&lt;host&gt;:&lt;port&gt;/job/test/5/consoleText

You can call this url the same way you would call any regular endpoint with Java (or any other language), and you will get the logs in plain text.

EDIT: Once the job has been triggered, that build will be the last one that has run in that job. Therefore. you can get the build number by calling:

http://&lt;host&gt;:&lt;port&gt;/job/test/lastBuild/buildNumber

In the same way you would call any other endpoint. This works even if you trigger multiple builds on the same job. Make sure you get the build number from the above URL and save it in an array every time you trigger a new job.

huangapple
  • 本文由 发表于 2023年7月13日 14:43:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76676582.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定