使用 Ant 获取存储库提交消息以更新使用 VSTS 或 Bitrise 构建的 Crashlytics Beta 发行说明

Getting repository commit messages with Ant to update Crashlytics Beta release notes for builds using VSTS or Bitrise

我对 CI 有点陌生,所以如果你们能提供给我尽可能多的细节,我将不胜感激。

我已经为不同的本机 Android 应用程序配置了两个构建服务器,一个使用 Bitrise,另一个使用 VSTS(Visual Studio Team Services),我还使用 Crashlytics/Beta 套件启用以在每个构建中自动分发 APK。 我需要添加一个构建步骤或一些配置,可能使用 Ant 或其他任何东西,以使用存储库中提交的消息更新上传到 Fabric 的每个构建的发行说明以进行测试。

提前致谢!


这是我的 VSTS 配置的屏幕截图

Powershell 脚本:

蚂蚁脚本:

以及 build.xml (Ant) 和 script_release_notes.txt (Powershell) 的屏幕截图,它们位于根文件夹中:

在 Bitrise 的情况下,如果您使用 Git Clone 步骤将提交信息公开为环境变量,然后您可以像任何其他环境变量一样在任何地方使用它。

您可以在此处找到 Git 克隆步骤的导出 "outputs"(环境变量)的完整列表:https://github.com/bitrise-io/steps-git-clone/blob/master/step.yml#L80

编辑:如果您想将这些保存到 release_notes.txt 文件中,您可以简单地 echo "$the_env_var" >> release_notes.txt,例如Script 个步骤。

要将完整的提交消息保存到发行说明中:

#!/bin/bash
# fail if any commands fails
set -e
# debug log
set -x

echo "$GIT_CLONE_COMMIT_MESSAGE_SUBJECT" > release_notes.txt
echo "$GIT_CLONE_COMMIT_MESSAGE_BODY" >> release_notes.txt

对于 VSTS 构建,您可以添加 PowerShell 脚本任务以通过 VSTS Rest API 获取当前构建的提交消息。

以下是一个示例 powershell 脚本,您需要在构建定义中启用 "Allow Scripts to Access OAuth Token" 选项才能使用此脚本。

$collectionuri = $env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI
$buildid = $env:BUILD_BUILDID
$project = $env:SYSTEM_TEAMPROJECT
$token = $env:SYSTEM_ACCESSTOKEN

$basicAuth= ("{0}:{1}"-f "anys",$token)
$basicAuth=[System.Text.Encoding]::UTF8.GetBytes($basicAuth)
$basicAuth=[System.Convert]::ToBase64String($basicAuth)
$headers= @{Authorization=("Basic {0}"-f $basicAuth)}

$url= $collectionuri + $project + "/_apis/build/builds/" + $buildID + "/changes?api-version=2.0"

$getbuildchanges = Invoke-RestMethod -Uri $url -headers $headers -Method Get | select value

foreach ($commit in $getbuildchanges.value)
{
    Write-Host $commit.id;
    $commit.id | Out-File -filepath commitmessages.txt -Append;
    Write-Host $commit.message;
    $commit.message | Out-File -filepath commitmessages.txt -Append;
}

更新:请尝试使用以下脚本:

$collectionuri = $env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI
$buildid = $env:BUILD_BUILDID
$project = $env:SYSTEM_TEAMPROJECT
$token = $env:SYSTEM_ACCESSTOKEN

$basicAuth= ("{0}:{1}"-f "anys",$token)
$basicAuth=[System.Text.Encoding]::UTF8.GetBytes($basicAuth)
$basicAuth=[System.Convert]::ToBase64String($basicAuth)
$headers= @{Authorization=("Basic {0}"-f $basicAuth)}

$url= $collectionuri + $project + "/_apis/build/builds/" + $buildID + "/changes?api-version=2.0"

$getbuildchanges = Invoke-RestMethod -Uri $url -headers $headers -Method Get;

if($getbuildchanges.count -ne 0)
{
foreach ($commit in $getbuildchanges.value)
{
    Write-Host $commit.id;
    $commit.id | Out-File -filepath release_notes.txt -Append;
    Write-Host $commit.message;
    $commit.message | Out-File -filepath release_notes.txt -Append;
}
}
else
{
    $nocommitfound = "There is no commit related to current build.";
    Write-Host $nocommitfound;
    $nocommitfound | Out-File -filepath release_notes.txt -Append;
}