Get pull request info on trigger with multiple VCS roots


Get pull request info on trigger with multiple VCS roots



I have a TeamCity (version 2017.2.4) project with multiple configurations which are attached to various GitHub repositories. Now I would like to setup SonarQube GitHub plugin for some of these configurations. To do so, I've created a new build and attached a VCS Trigger. In order to make this trigger work, I also attached all VCS roots which I'd like this build to run on. Now after any changes in these VCS roots, the build gets triggered.


VCS Trigger



In order to use this plugin, after each trigger I need to extract repository name which was affected and fetch the pull request id. This is easy to do if I have a single VCS root with the following script:


#!/usr/bin/env bash

# Exit script on any command failure.
set -e

# Pass parameter to next TeamCity build step.
param() {
echo "##teamcity[setParameter name='$1' value='$2']"
}

# Full GitHub repository name.
repository="myOrg/$(echo '%vcsroot.url%' | grep -oP '(?<=/).*(?=.git)')"

# Full URL to fetch branch pull request info.
url="https://api.github.com/repos/${repository}/pulls"
url="${url}?head=%teamcity.build.branch%"
url="${url}&access_token=%github.authToken%"

echo "Fetching PR information from: ${url}"
res=$(curl "${url}" -f)

echo "Parsing PR id from:"
echo "${res}"
pullRequest=$(echo "${res}" | grep -oP -m 1 '(?<=pulls/)d+(?=",)')

if [ -z "${pullRequest}" ]; then
echo "Could not parse PR id from: ${res}"
exit 1
fi

# Pass parameters to next build step which will init the plugin.
param 'github.pullRequest' ${pullRequest}
param 'github.repository' ${repository}



However since I have multiple VCS roots, I'm not able to refer to %vcsroot.url%, so:


%vcsroot.url%



This question has not received enough attention.









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

how to run turtle graphics in Colaboratory

Export result set on Dbeaver to CSV