2

在 AppVeyor 中,我想使用来自 Github 的版本号设置内部版本号。这将用于 AssemblyVersion 修补。

我正在使用 GitFlow,并且有一个发布分支。在 SourceTree 中,我创建了一个新版本,例如 v1.2,它创建了分支 release/v1.2。我想在 AppVeyor 中使用的 1.2 部分。

比如,构建版本格式:{gitRelease}.{build}

屏幕截图 AppVeyor 构建 nr

为此,

  1. 我需要检索 gitHub 分支名称,
  2. 从中提取版本号,
  3. 把它放在一个变量 {gitRelease}
  4. 在 assemblyVersion 修补之前运行它

但我找不到如何做到这一点。

对于构建本身,我有一个构建脚本,将输出(nuget 包)发送到 Octopus Deploy,这意味着没有构建脚本之前的部分。

4

2 回答 2

2

您可以从环境变量中获取版本号,对其进行处理并使用 AppVeyor build worker API 发回:

$version = $env:appveyor_build_version
# ... do something with it
Update-AppveyorBuild -Version $version
于 2015-10-02T16:57:49.630 回答
2

在 AppVeyor 支持人员的帮助下,我得到了它的工作。 1733-how-to-call-the-assemblyversion-patch-from-the-build-script

我必须使用 appveyor.yml 中的 init 部分。我为 UpdateBuild - 版本使用了单独的 cmd 行(我在使用 qoutes 时遇到了一些问题)。

init:
- cmd: "set appVeyorBuildVersion=%appveyor_build_version%\necho appVeyorBuildVersion:%appVeyorBuildVersion% \n\nset branch=%APPVEYOR_REPO_BRANCH%\necho branch:%branch%\n\nset gitVersion=%branch:~-3%\necho gitversion:%gitVersion%\n\nset newVersion=%gitVersion%.%APPVEYOR_BUILD_NUMBER%\necho %newVersion%\n\n"
- cmd: appveyor UpdateBuild -Version "%newVersion%"

assembly_info:
  patch: true
  file: '**\AssemblyInfo.*'
  assembly_version: '{version}'
  assembly_file_version: '{version}'
  assembly_informational_version: '{version}'
build_script:
- cmd: "echo Building version:%appveyor_build_version%"
- cmd: "nuget restore\nmsbuild MySolution.sln /t:build /p:Configuration=Release"

命令行部分(可读性更好):

echo repo branch:%APPVEYOR_REPO_BRANCH%

set branch=%APPVEYOR_REPO_BRANCH%
echo branch:%branch%

set gitVersion=%branch:~-4%
echo gitversion:%gitVersion%


set newVersion=%gitVersion%.%APPVEYOR_BUILD_NUMBER%
echo %newVersion%

appveyor UpdateBuild -Version "%newVersion%"
于 2015-10-05T18:43:34.820 回答