tfs - 使用 Octopus 部署特定版本的 NuGet 包

标签 tfs octopus-deploy

我们在 TFS 上进行了自动构建,可在 Octopus 中创建一个版本,并自动部署到测试环境。

作为此构建的一部分,我们提供 --defaultpackageversion与我们的发布路线图一致的值,例如4.1.1.1 - 此版本在构建模板中分配,所有项目都正确地使用该版本进入 Octopus。

作为此版本的一部分,有一个来 self 们的 NuGet 远程源的软件包不反射(reflect)发布路线图版本,例如1.1.0.0 .

因此,对于 Octopus 部署的每个包 4.1.1.1 ,但尝试解析 4.1.1.1对于这个特定的包,只有 1.1.0.0存在。

octo.exe 有一个参数,允许我们为给定步骤提供版本 --package=StepName .

要提供此步骤名称的版本,我需要:

  1. Get the NuGet package ID
  2. Use NuGet to get the latest version for this package
  3. Pipe this version with the step name into octo.exe

这意味着必须指定(作为 TFS 构建模板的一部分)NuGet 包 ID 和部署所述包的 Octopus Step。因此,如果步骤更改为部署不同的 NuGet 包,我必须在提供此参数的每个构建模板中反射(reflect)该更改。

在我看来,我应该能够:

  1. Tell Octopus to deploy a specific version of a NuGet package, without providing a particular step.
  2. Tell Octopus to automatically get the latest version of a NuGet package given a step name.

我看不到任何可以让我实现上述任一选项的论据。

有谁知道如何实现上述任一选项(或类似的选项)?否则,我可能必须在构建模板中指定步骤名称和 NuGet 包 ID(不理想)。

最佳答案

很抱歉回答我自己的问题,但想为我们最终采用的解决方案添加更多细节。

因此,我向构建模板“部署最新的 NuGet 包的步骤”添加了一个新参数。此参数包含以逗号分隔的 Octopus 步骤/NuGet 包对列表 - 这些由冒号分隔,例如

"Deploy Web Site:Company.Common,Deploy Database:Company.Project.Database".

构建事件将参数分成各自的对。它使用 NuGet list 启动一个进程来识别每个包的最新版本。然后,我们使用 Regex 来确定最新版本:

....
var output = p.StandardOutput.ReadToEnd();
var pattern = string.Format(@"^{0}\s(?<version>\d+\.\d+\.\d+\.\d+)\r?$", package.NuGetPackageId);

package.Version = Regex.Matches(output, pattern, RegexOptions.Multiline).
    OfType<Match>().
    Select(r => new Version(r.Groups["version"].Value)).
    Max();

其中 p 是 NuGet 进程,package 是带有步骤名称、NuGet 包 ID 和版本属性的 POCO。

然后使用 --package 参数将该特定步骤名称、版本对提供给 octopus,例如

--package "Deploy Web Site:4.1.1.1,Deploy Database:1.1.0.0"

希望这对将来的人有一些帮助。

关于tfs - 使用 Octopus 部署特定版本的 NuGet 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28747974/

相关文章:

web-config - 替换 Octopus Deploy 的 web.config 元素

tfs - 如何在 Team Foundation Service 中查看其他人的工作项?

c# - TFS 2010 - 为什么我在模拟时收到 "TF30063 You are not authorized to access.."错误?

c# - 无法从传输连接读取数据 - TFS 问题

.net-core - Dotnet publish with .NET core 2.0 和 .NET Framework 项目

TFS 2012 未将转换后的 Web.Config 复制到 _PublishedWebsite

tfs - 在 TFS 版本控制 SDK (Microsoft.TeamFoundation.VersionControl) 的上下文中,deletionID 到底是什么?

tfs - 构建计数器 - Visual Studio 团队服务

sql-server - 如何从 PowerShell 运行 sp_configure 'Ad Hoc Distributed Queries'?

teamcity - 如何在 nuget 包中包含一个目录