In a configuration to build HEAD of all open pull requests in Github each build has a branch , i.e refs/pull/133/head that has the PR number.
Tried to get the build object's branch attribute but it returns empty. Any ideas how to get this branch or just the PR number?
Where did you try to get PR number? From RESTful API? If you are using RESTful API (http://your.qb.server/rest/builds/{buildId}), you can read shortBranch
from the result like below:
<shortBranch>refs/pull/1/head</shortBranch>
<shortBranchRepo>github</shortBranchRepo>
Hi @steveluo. I work with@mshalev, and am the reason he asked this question in the first place. I figured I had better create an account and reply directly, rather than asking him to translate, so to speak.
I'm looking to get the GitHub PR number in a build step - currently we send the revision ID (via ${repositories.get("MyGithubRepo").revision}
) to a PowerShell script and try to determine the PR via GitHub's own REST API, but it sometimes returns too many PR's back if there are multiple targeting the same branch, so I need the specific PR that triggered the build in question.
I tried using ${repositories.get("MyGithubRepo").getBranch()}
and ${repositories.get("MyGithubRepo").branch()}
as the docs for com.pmease.quickbuild.plugin.scm.github.GitHubRepository
show a getBranch()
method. But when I call this in my build, it returns an empty string, so no bueno.
Any help you can provide would be much appreciated. We are using QuickBuild v7.0.10.
Sorry for the late reply, hope you have already found the solution.
If not, hope below scripts can help:
${build.getShortBranch()}
or
${repositories.get("MyGithubRepo").getShortBranches()}
or
${repositories.get("MyGithubRepo").getAcutalBranch()}
I had gone ahead and implemented the solution using the REST API, but this is much, much simpler, and I verified that ${build.getShortBranch}
gives me the same thing, so I will implement that instead as time allows, as that saves me the trouble of storing an additional set of credentials. Thanks!