我们在 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
.
要提供此步骤名称的版本,我需要:
- Get the NuGet package ID
- Use NuGet to get the latest version for this package
- Pipe this version with the step name into
octo.exe
这意味着必须指定(作为 TFS 构建模板的一部分)NuGet 包 ID 和部署所述包的 Octopus Step。因此,如果步骤更改为部署不同的 NuGet 包,我必须在提供此参数的每个构建模板中反射(reflect)该更改。
在我看来,我应该能够:
- Tell Octopus to deploy a specific version of a NuGet package, without providing a particular step.
- 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/