通过github api获取构建状态

时间:2015-04-04 06:38:41

标签: github github-api

GitHub API提供了很多功能,但有没有办法检索提交的构建状态? GitHub UI提供了我们配置的CI系统的信息,但是我无法通过API看到这些信息?

2 个答案:

答案 0 :(得分:4)

You can access the status for a particular ref

GET https://api.github.com/repos/:owner/:repo/commits/:ref/statuses

对于:ref的值,您可以使用SHA,分支名称或标记名称。

答案 1 :(得分:3)

它没有直接提供状态,但可以提供 create a status

这意味着CI可以有一个最终构建步骤,以这种方式将状态发布到GitHub repo。

POST /repos/:owner/:repo/statuses/:sha

例如:

{
  "state": "success",
  "target_url": "https://example.com/build/status",
  "description": "The build succeeded!",
  "context": "continuous-integration/jenkins"
}

(对于给定的SHA1)


例如参见" Github Commit Status API with Bamboo from Atlassian":

  

将这些内容添加到您的计划中作为脚本。

  • complete.sh

    # specs and cukes results are stored in JUnit format under test-reports
    if (grep 'failures="[^0]"' test-reports/* || grep 'errors="[^0]"' test-reports/*); then
      curl -H "Authorization: token MY_TOKEN" --request POST --data '{"state": "failure", "description": "Failed!", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos/USER/REPO/statuses/${bamboo.repository.revision.number} > /dev/null
    else
      curl -H "Authorization: token MY_TOKEN" --request POST --data '{"state": "success", "description": "Success!", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos/USER/REPO/statuses/${bamboo.repository.revision.number} > /dev/null
    fi
    
  • pending.sh

    curl -H "Authorization: token MY_TOKEN" --request POST --data '{"state": "pending", "description": "Build is running", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos/USER/REPO/statuses/${bamboo.repository.revision.number} > /dev/null