Jenkins: Get build numbers range on a particular day

后端 未结 2 1006
悲哀的现实
悲哀的现实 2021-01-14 14:59

For data mining reasons, I want to get build numbers range of a jenkins job that were built on a particular day. Is there a plugin that accomplishes this or any other possib

相关标签:
2条回答
  • 2021-01-14 15:42

    The built-in REST JSON API will give you a list of the builds for a particular job: http://jenkins:8080/job/JOB_NAME/api/json?tree=builds[fullDisplayName,id,number,timestamp]&pretty=true

    Produces something like:

    {
      "builds" : [
        {
          "fullDisplayName" : "JOB_NAME #113",
          "id" : "2014-10-31_23-05-20",
          "number" : 113,
          "timestamp" : 1414821920808
        },
        {
          "fullDisplayName" : "JOB_NAME #112",
          "id" : "2014-10-31_17-26-39",
          "number" : 112,
          "timestamp" : 1414801599000
        },
        ....
    

    If your build ids are the basic date-stamp (as above), you can do a little string processing to filter the results. Otherwise, you can convert the timestamp to the appropriate date and filter on that.

    Most Jenkins pages have a REST API link at the bottom that provides more documentation, though you often need to experiment with the API to figure out what details it can provide.


    Update: As @Nick discovered, the builds result is limited to the latest 100 elements by default. According to this Jenkins issue, you can use the hidden allBuilds element to retrieve "all builds". So if you need all builds, use: http://jenkins:8080/job/JOB_NAME/api/json?tree=allBuilds[fullDisplayName,id,number,timestamp]&pretty=true

    Jenkins 1.568 also introduced pagination in the API results, so it's possible to retrieve results by range. The Jenkins REST API link describes the syntax if your Jenkins version supports it.

    0 讨论(0)
  • 2021-01-14 15:44

    There is the Global Stats Plugin

    Which also has a JSON REST API

    0 讨论(0)
提交回复
热议问题