我有一个TeamCity(版本2017.2.4)项目,该项目具有多个配置,这些配置已附加到各个GitHub存储库中。现在,我想为其中一些配置设置SonarQube GitHub plugin。为此,我创建了一个新版本并附加了VCS Trigger
。为了使该触发器起作用,我还附加了希望在其上运行的所有VCS根目录。现在,在对这些VCS根目录进行任何更改之后,便会触发构建。
为了使用此插件,在每次触发后,我需要提取受影响的存储库名称并获取拉取请求ID。如果我有一个带有以下脚本的VCS根,这很容易做到:
#!/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}
但是,由于我有多个VCS根目录,因此无法引用%vcsroot.url%
,因此: