【问题标题】:Insert teamcity artifact pathTeamcity into powershell script将 teamcity 工件 pathTeamcity 插入到 powershell 脚本中
【发布时间】:2016-10-17 20:46:06
【问题描述】:

我正在将一个项目添加到 teamcity 中,并且需要添加一个 powershell 脚本来更改一些配置设置并生成一个压缩的工件。我已经在 teamcity 之外构建并测试了脚本文件,但为了使其在构建期间工作,我需要获取构建工件的路径。

有没有办法将c:\artifacts\myproject\build\38 下方的代码中的代码替换为始终获取最新构建目录的 teamcity 参数?

#Find and replace various app.config settings
$location = C:\Artifacts\MyProject\Build\38\myApp\myConfig.config";
(Get-Content $location) | 
ForEach-Object { $_ -replace '<add key="platform" value="xxxx"/>', '<add key="platform" value="test"/>' } |
Set-Content $location   

#Should take source directory and create a zip file from it
$source = "C:\Artifacts\MyProject\Build\38\myApp\"
$destination = "C:\Artifacts\FrontOfficeApi\Build\38\artifact.zip"

GenerateZipFile -DestinationFilePath $destination -SourcePath $source

非常感谢

【问题讨论】:

    标签: powershell teamcity


    【解决方案1】:

    $buildDirectory = "%teamcity.build.chec‌​koutDir%" 会给你源代码签出到的目录,这样你就可以从那里相对地工作。这是如果您将 PowerShell 作为源代码运行,否则您可以使用相同的变量将参数传递到 PowerShell 脚本中。

    希望对你有帮助

    【讨论】:

    • 感谢您的回复。我决定做的是尝试将 teamcity.build.checkoutDir 的值输出到物理文件。这有几个原因。 1. 根据我自己对 teamcity 工作原理的了解,以及 2. 这是一个更简单的脚本。
    • 但是,当我添加 PS 构建步骤并运行构建时,我收到一条错误消息,指出没有兼容的构建代理。当我禁用新步骤时,构建运行良好!设置为:Powershell 运行模式:任意,位:x86,脚本:源代码,脚本:$buildDirectory = "%teamcity.build.chec‌​koutDir%" $buildDirectory |输出文件 c:\debug.txt。脚本执行模式:从外部文件执行.ps1。任何建议都会非常感谢。
    猜你喜欢
    • 2017-05-20
    • 2015-11-18
    • 2014-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-25
    • 1970-01-01
    • 2022-11-17
    相关资源
    最近更新 更多