TeamCity 在工件 zip 名称中显示分支
TeamCity show branch in artifact zip name
我在 TeamCity 中有一个构建,我想在其中构建一个工件 zip 文件。
我可以使用 Edit Configuration Settings => General Settings => Artifact Paths
设置要压缩的文件和压缩文件名。
我想让名称更具描述性,TeamCity 允许我使用参数,例如:
out/mypackagedfiles/** => MyBuild_%build.number%.zip
会给我一个类似 MyBuild_46.zip
.
的 zip 文件
我还想包括构建构建的分支。这也可用作 TeamCity 参数,但它包含一个正斜杠(例如 feature/my_great_feature
)。因此,如果我在 Artifact Paths
配置中使用它,我会得到一个包含 zip 文件的目录:
out/mypackagedfiles/** => MyBuild_%build.number%_%vcsroot.branch%.zip
在名为 MyBuild_46_feature
.
的目录中给出 my_great_feature.zip
我想做的是以某种方式 remove/replace 分支名称的正斜杠得到一个 zip 文件,例如 MyBuild_46_feature_my_great_feature.zip
.
我不担心确切的格式 - 只要分支名称是可识别的。
可能存在的想法 - 但我还找不到:
- 创建一个新参数,该参数从
vcsroot.branch
派生经过清理的分支名称
Artifact Paths
配置中的某种字符串操作
== 编辑 ==
基于下面的 oryades 回答(看起来像 linux bash 命令行),我将其转换为 PowerShell for Windows如下:
- 设置工件以使用 %env.branch_name%(这还需要在构建的“参数”选项卡中将 temporary/dummy 值设置为 运行)
- 使用 运行ner type = PowerShell
创建构建步骤
将脚本设置为源代码并粘贴以下内容:
$branch_name="%vcsroot.branch%".replace('/','_')
echo "Sanitised branch for Artifact zip = " $branch_name
echo "##teamcity[setParameter name='env.branch_name' value='$branch_name']"
请注意,TeamCity 允许您替换 %vcsroot.branch% - 这是在 PowerShell 运行s 之前发生的替换。感谢 Team City and Power Shell 提供此提示
您可以在构建过程中创建环境变量,只需创建一个具有以下内容的构建步骤:
branch_name=$(echo %vcsroot.branch% | sed 's/\//_/')
echo "##teamcity[setParameter name='env.branch_name' value='$branch_name']"
在接下来的构建步骤中,您可以使用 %env.branch_name% 作为具有所需值的变量。
https://confluence.jetbrains.com/display/TCD10/Build+Script+Interaction+with+TeamCity
我在 TeamCity 中有一个构建,我想在其中构建一个工件 zip 文件。
我可以使用 Edit Configuration Settings => General Settings => Artifact Paths
设置要压缩的文件和压缩文件名。
我想让名称更具描述性,TeamCity 允许我使用参数,例如:
out/mypackagedfiles/** => MyBuild_%build.number%.zip
会给我一个类似 MyBuild_46.zip
.
我还想包括构建构建的分支。这也可用作 TeamCity 参数,但它包含一个正斜杠(例如 feature/my_great_feature
)。因此,如果我在 Artifact Paths
配置中使用它,我会得到一个包含 zip 文件的目录:
out/mypackagedfiles/** => MyBuild_%build.number%_%vcsroot.branch%.zip
在名为 MyBuild_46_feature
.
my_great_feature.zip
我想做的是以某种方式 remove/replace 分支名称的正斜杠得到一个 zip 文件,例如 MyBuild_46_feature_my_great_feature.zip
.
我不担心确切的格式 - 只要分支名称是可识别的。
可能存在的想法 - 但我还找不到:
- 创建一个新参数,该参数从
vcsroot.branch
派生经过清理的分支名称
Artifact Paths
配置中的某种字符串操作
== 编辑 ==
基于下面的 oryades 回答(看起来像 linux bash 命令行),我将其转换为 PowerShell for Windows如下:
- 设置工件以使用 %env.branch_name%(这还需要在构建的“参数”选项卡中将 temporary/dummy 值设置为 运行)
- 使用 运行ner type = PowerShell 创建构建步骤
将脚本设置为源代码并粘贴以下内容:
$branch_name="%vcsroot.branch%".replace('/','_') echo "Sanitised branch for Artifact zip = " $branch_name echo "##teamcity[setParameter name='env.branch_name' value='$branch_name']"
请注意,TeamCity 允许您替换 %vcsroot.branch% - 这是在 PowerShell 运行s 之前发生的替换。感谢 Team City and Power Shell 提供此提示
您可以在构建过程中创建环境变量,只需创建一个具有以下内容的构建步骤:
branch_name=$(echo %vcsroot.branch% | sed 's/\//_/')
echo "##teamcity[setParameter name='env.branch_name' value='$branch_name']"
在接下来的构建步骤中,您可以使用 %env.branch_name% 作为具有所需值的变量。
https://confluence.jetbrains.com/display/TCD10/Build+Script+Interaction+with+TeamCity