From Jenkins, how do I get a list of the currently running jobs in JSON?

前端 未结 6 1828
执笔经年
执笔经年 2020-12-07 17:41

I can find out just about everything about my Jenkins server via the Remote API, but not the list of currently running jobs.

This,

http://my-jenkins         


        
6条回答
  •  渐次进展
    2020-12-07 18:37

    There is often confusion between jobs and builds in Jenkins, especially since jobs are often referred to as 'build jobs'.

    • Jobs (or 'build jobs' or 'projects') contain configuration that describes what to run and how to run it.
    • Builds are executions of a job. A build contains information about the start and end time, the status, logging, etc.

    See https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project for more information.

    If you want the jobs that are currently building (i.e. have one or more running builds), the fastest way is to use the REST API with XPath to filter on colors that end with _anime, like this:

    http://jenkins.example.com/api/xml?tree=jobs[name,url,color]&xpath=/hudson/job[ends-with(color/text(),%22_anime%22)]&wrapper=jobs
    

    will give you something like:

    
      
        PRE_DB
        http://jenkins.example.com/job/my_first_job/
        blue_anime
      
      
        SDD_Seller_Dashboard
        http://jenkins.example.com/job/my_second_job/
        blue_anime
      
    
    

    Jenkins uses the color field to indicate the status of the job, where the _anime suffix indicates that the job is currently building.

    Unfortunately, this won't give you any information on the actual running build. Multiple instances of the job maybe running at the same time, and the running build is not always the last one started.

    If you want to list all the running builds, you can also use the REST API to get a fast answer, like this:

    http://jenkins.example.com/computer/api/xml?tree=computer[executors[currentExecutable[url]],oneOffExecutors[currentExecutable[url]]]&xpath=//url&wrapper=builds
    

    Will give you something like:

    
      http://jenkins.example.com/job/my_first_job/1412/
      http://jenkins.example.com/job/my_first_job/1414/
      http://jenkins.example.com/job/my_second_job/13126/
    
    

    Here you see a list off all the currently running builds. You will need to parse the URL to separate the job name from the build number. Notice how my_first_job has two builds that are currently running.

提交回复
热议问题