Run a custom build on a Pull request
Hi team,
I have a Teamcity (TC) builds on repo A and repo B. Repo B contains integration tests of Repo A and its dependencies.
I tried to run TC build of Repo A when pull request (PR) is raised on Repo B using PR build feature and VCS trigger and didn't work.
Could you let me know if the above mentioned usecase can be implemented in TC? if yes, could you share the steps to implement ? thanks in advance.
Please sign in to leave a comment.
In the meantime, what I understood from your description so far is this:
* One of your build configurations should start a build when there is a new pull request raised in Repo B.
* The triggered build should check out Repo A.
That is possible with the following configuration:
1. Attach both Repo A and Repo B VCS Roots to the build configuration.
2. Don't include pull request refs in the VCS Roots branch specification
(a GitHub example of a pull request ref would be refs/pull/123/heads).
3. Add the Pull Requests build feature and make it watch the Pull Requests of the Repo B VCS Root.
4. Add a VCS Trigger and make it fire on creating/updating Pull Requests by setting its Branch Filter field to
`+:pull/*`.
5. If you want to trigger the build only by the pull requests in Repo B, but not Repo A, set the Trigger Rules to something like `+:root=Repo_B:**`.
Please note that VCS Trigger will only start builds against pull requests that have been created or updated after the trigger was configured.
Alternatively, if there is a snapshot dependency, it is also possible to trigger a build off of the changes in the VCS Root of the snapshot-dependent configuration. As I mentioned, I am not sure what your use case is, so it hard to provide relevant recommendations.
Hi Anatoly Cherenkov Thanks for the quick reply.
In my case, repo-A builds the docker images of all dependent components, deploys to local docker env and run integration tests.
Here is a list of TC changes at a high level.
1. A new build type named "Run integration tests" has been added to the TC build configuration of Repo-A and it does following
a. Add a Repo-A's integration build to TC build queue by invoking Rest API
b. Wait for the build to succeed or fail by polling status of above initiated build using build id.
2. Added Pull Requests build feature to "Run integration tests" build and configured it to watch the pull requests of the Repo-B vcs root.
(using bitbucket)
features {pullRequests {
vcsRootExtId = DemoAppVcsRoot.id.toString()
provider = bitbucketServer {
serverUrl = "https://stash.mybitbuckethost.com"
authType = token {
token = "***********"
}
}
}
}
3. Pull request build feature is creating internal branches with pattern `pull-requests/<pull-request-id>`. so, Added VcsTrigger to "Run integration tests" build to trigger a build on pull requests branch.
triggers {vcs {
branchFilter = "+:pull-requests/*"
}
}
The above setup correctly initiated the "Run integration tests" build that executes integration tests build of Repo-A. However, `%teamcity.build.branch%` returning "pull-requests/<pull-request-id>" instead of source branch of the pull request i.e Repo-B feature branch.
To build docker image on latest code, Repo-A TC build requires Repo-B feature branch name, which is the source branch of the PR. is it possible get source branch of the PR?
Let me know if you have any questions. thanks.
I figured out that pull request build feature is setting source branch to `teamcity.pullRequest.source.branch` param.
One last thing pending on this, How to link PR triggered builds into bitbucket PR's build section. I am able to see the vcs trigger builds in build section of the PR but not PR build feature triggered builds. is there a way to link PR feature builds to bitbucket PR's build section ?