【问题标题】:Getting TeamCity to recognize Powershell messages让 TeamCity 识别 Powershell 消息
【发布时间】:2012-09-20 22:10:45
【问题描述】:

如何让 TeamCity 使用 Powershell 在构建日志中输出消息?

我正在使用 TeamCity 7.1。

这是我的 Powershell 构建步骤:

脚本是:

write-host "##teamcity[message 'Getting production info']"

if ($LASTEXITCODE -ne 0) {
    write-host "##teamcity[message 'Production Remote Not Found: Creating Remote']"

    write-host "##teamcity[message 'Pushing to Remote']"
    #git push production

} else {
    write-host "##teamcity[message 'write-output: Production Remote Found: Pushing to Remote']"
    #git push production
}

我在构建日志中得到的唯一信息是:

[17:02:58]Skip checking for changes - changes are already collected
[17:02:59]Publishing internal artifacts (1s)
[17:03:00][Publishing internal artifacts] Sending build.start.properties.gz file
[17:02:59]Clearing temporary directory: C:\BuildAgent2\temp\buildTmp
[17:02:59]Checkout directory: C:\BuildAgent2\work\7669b6a04f96908d
[17:02:59]Updating sources: agent side checkout
[17:02:59][Updating sources] VCS Root: Portal Master
[17:02:59][VCS Root: Portal Master] revision: c5c6a9a0d491ee2c64ce98e48b0d67c422237698
[17:02:59][VCS Root: Portal Master] Resetting Portal Master in C:\BuildAgent2\work\7669b6a04f96908d to revision c5c6a9a0d491ee2c64ce98e48b0d67c422237698
[17:02:59]Starting: C:\Windows\sysnative\cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -File C:\BuildAgent2\temp\buildTmp\powershell1349912883332714566.ps1
[17:02:59]in directory: C:\BuildAgent2\work\7669b6a04f96908d
[17:03:00]
[17:03:00]
[17:03:00]
[17:03:00]Process exited with code 0
[17:03:00]Publishing internal artifacts
[17:03:00][Publishing internal artifacts] Sending build.finish.properties.gz file
[17:03:00]Build finished

【问题讨论】:

    标签: powershell teamcity-7.0


    【解决方案1】:

    documentation中所述,“消息”服务消息可以有多个参数,因此您至少需要指定参数“文本”:"##teamcity[message text='Getting production info']"

    您的脚本将是

    write-host "##teamcity[message text='Getting production info']"
    
    if ($LASTEXITCODE -ne 0) {
        write-host "##teamcity[message text='Production Remote Not Found: Creating Remote']"
    
        write-host "##teamcity[message text='Pushing to Remote']"
        #git push production
    
    } else {
        write-host "##teamcity[message text='write-output: Production Remote Found: Pushing to Remote']"
        #git push production
    }
    

    【讨论】:

    • +1 @JoeYoung 我刚被这个刺痛了,但是,根据docs,您不必显式定义text 属性;这被视为单个属性消息,应该可以工作。但是,它并没有,使用 text 可以解决问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-20
    • 2019-09-20
    相关资源
    最近更新 更多