22

特定のジョブが現在実行中かどうかを判断する API はありますか?

Ideally, I'd also like to be able to determine its estimated % complete and get the details of the SVN revision number and commit comment too!

EDIT:

I found the answer. http://host/job/project/lastBuild/api/ has almost all of what I need in it somewhere! If you kick off a manual build, it won't tell you the SCM changesets, but that makes sense. It does still tell you the latest SCM revision though, so that's good. All in all, good enough for my purposes right now.

4

6 に答える 6

22

gareth_bowles と Sagar が言ったように、Jenkins API を使用することが知る方法です。深さを 1 にすると、探しているものが表示されます。

http://host/job/project/lastBuild/api/xml?depth=1

<building>そのビルドが実行されているかどうかを示すタグがあることがわかります

...
<build>
  <action>
    <cause>
        <shortDescription>Started by user Zageyiff</shortDescription>
        <userId>Zageyiff</userId>
        <userName>Zageyiff</userName>
    </cause>
  </action>
  <building>true</building>
  <duration>0</duration>
  <estimatedDuration>-1</estimatedDuration>
  <fullDisplayName>Project #12</fullDisplayName>
  <id>2012-08-24_08-58-45</id>
  <keepLog>false</keepLog>
  <number>12</number>
  <timestamp>123456789</timestamp>
  <url>
        http://host/job/project/12
  </url>
  <builtOn>master</builtOn>
  <changeSet/>
  <mavenVersionUsed>3.0.3</mavenVersionUsed>
</build>
...
于 2012-08-24T13:11:31.790 に答える
7

私は Groovy プラグインを使用しており、次のスニペットをシステムとして実行しています。

import hudson.model.*
def version = build.buildVariableResolver.resolve("VERSION")
println "VERSION=$version"
def nextJobName = 'MY_NEXT_JOB'
def nextJob = Hudson.instance.getItem(nextJobName)
def running = nextJob.lastBuild.building
if (running) {
   println "${nextJobName} is already running. Not launching"
} else {
   println "${nextJobName} is not running. Launching..."
   def params = [
      new StringParameterValue('VERSION', version)
   ]
   nextJob.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(params))
}

それは魅力のように機能します。

于 2014-07-23T15:07:46.937 に答える
5

求人のページに移動し、URL の末尾に「api」を追加すると、API の使用に関する情報が表示されます。

http://yourjenkins/job/job_name/api

Jenkins API の使用に関する詳細情報:

https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API
于 2011-09-02T16:14:56.537 に答える
2

Jenkins Java API を詳しく調べることに慣れている場合は、システムの Groovy スクリプトを記述してこのデータを取得できます。Job クラスが出発点です 。

于 2011-09-02T18:08:15.113 に答える