远程触发构建后检查Jenkins作业状态 [英] Check Jenkins job status after triggering a build remotely

查看:474
本文介绍了远程触发构建后检查Jenkins作业状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,可以使用令牌远程触发Jenkins上的作业.这是我的脚本:

I have a script to trigger a job on Jenkins remotely using a token. Here is my script:

JENKINS_URL='http://jenkins.myserver.com/jenkins'
JOB_NAME='job/utilities/job/my_job'
JOB_TOKEN='my_token'

curl "${JENKINS_URL}/${JOB_NAME}/buildWithParameters?token=${JOB_TOKEN}"

运行它后,得到以下响应:

* Hostname was NOT found in DNS cache
*   Trying 10.5.187.225...
* Connected to jenkins.myserver.com (10.5.187.225) port 80 (#0)
> GET /jenkins/job/utilities/job/my_job/buildWithParameters?token=my_token HTTP/1.1
> User-Agent: curl/7.37.1
> Host: jenkins.myserver.com
> Accept: */*
> 
< HTTP/1.1 201 Created
* Server nginx/1.6.2 is not blacklisted
< Server: nginx/1.6.2
< Date: Tue, 03 Feb 2015 23:40:47 GMT
< Content-Length: 0
< Location: http://jenkins.myserver.com/jenkins/queue/item/91/
< Connection: keep-alive
< Cache-Control: private
< Expires: Wed, 31 Dec 1969 16:00:00 PST
< 
* Connection #0 to host jenkins.myserver.com left intact

我注意到它返回了标题中的队列URL: http://jenkins. myserver.com/jenkins/queue/item/91 .但我不知道该如何使用此返回网址.

I noticed that it returns the queue url in the header: http://jenkins.myserver.com/jenkins/queue/item/91. But I don't know how I should use this return url.

1)我想知道是否有人知道如何检查我刚刚创建的工作的状态?

1) I am wondering if anyone knows how I can check the status for the job that I just created?

2)由于上述响应未返回工作号,因此我无法真正使用此api调用:

2) Since the above response does not return the job #, I can't really use this api call:

curl http://jenkins.myserver.com/jenkins/job/utilities/job/my_job/8/api/json

检查状态.那么从上述响应中获得位置网址后,我在哪里可以得到工作名称和工作编号?

to check for status. So where can I get the job name and job number after I get the location url from the above response?

谢谢

推荐答案

触发作业时,该作业将放入队列中.仅在开始运行时才创建实际的构建,并在那时获得该构建的编号.如果您的所有执行者都很忙,有时可能要花很长时间才能创建构建并开始运行.

When you trigger a job, the job is placed into the queue. The actual build is created only when it starts running and at that point the build gets a build number. If all your executors are busy, it can sometimes take a long time before the build is created and starts running.

触发作业时获取内部版本号的唯一方法是使用

The only way to get the build number when triggering a job, is to use the "build" command of the Jenkins CLI. If you use the -w option, the command will not return until the build starts and then it will print "Started build #N"

您实际上不需要Java cli.jar,只需一个ssh客户端就足够了.参见 https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+ SSH

You do not actually need the java cli.jar, just an ssh client is enough. See https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+SSH

除此之外,没有已知的解决方案.您也许可以搜索这些构建,并找到一个在您完成工作时就被触发的构建,但这是很多工作.

Other than that there is no known solution. You might be able to search through the builds and find a one that was triggered around the time your triggered the job, but that's a lot of work.

这篇关于远程触发构建后检查Jenkins作业状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆