【问题标题】:How do you get powershell script output in the deployment log for a vNext Release Template?如何在 vNext 发布模板的部署日志中获取 powershell 脚本输出?
【发布时间】:2015-01-14 17:38:21
【问题描述】:

这篇博文是我发现的唯一一个接近问题的东西,但它没有解释如何配置使用 PS/DSC 部署以使用详细选项运行: http://nakedalm.com/create-log-entries-release-management/

我可以获得这个基于代理的发布模板来运行脚本:

Write-Debug "debug"
Write-Output "output"
Write-Verbose "verbose"
Write-Warning "warning"

此版本的深入部署日志提供了一个包含以下行的日志:

output
WARNING: warning

如果我将 -verbose 添加到 Arguments 字段,我还会在日志中看到“VERBOSE: verbose”行。

这很好,但我需要访问系统变量($Stage、$BuildNumber 等)。当我创建一个 vNext 模板来运行相同的脚本时(说明在这里:http://www.visualstudio.com/en-us/get-started/deploy-no-agents-vs.aspx),日志报告:

Copying recursively from \\vsalm\Drops2\TestBuild\TestBuild_20130710.3 to c:\Windows\DtlDownloads\my vnext component succeeded.

很高兴这个复制操作成功了,但是我希望我的脚本输出也能在这个日志中。有没有人知道配置“使用 PS/DSC 部署”操作以便发布管理捕获 powershell 脚本输出?

【问题讨论】:

    标签: powershell release-management ms-release-management


    【解决方案1】:

    对于 vNext 发布模板,如果您想在日志中查看 powershell 脚本输出,请尝试使用带有 -verbose 开关的 Write-Verbose

    例如。 Write-Verbose "Some text" -verbose

    【讨论】:

    • 这可行,但我的版本中有一个 try/catch 块,之后不再写入消息,而该部分中的操作执行得很好......
    【解决方案2】:

    请允许我无耻地插入my own blog article 关于这个主题,因为我发现要得到一个能把所有事情都做好的脚本并不容易。

    以下脚本框架确保记录的标准输出输出没有空行,并且处理在第一个错误时停止,在这种情况下,错误详细信息和到该点的标准输出在 MSRM 中都是可见的:

    function Deploy()
    {
        $ErrorActionPreference = "Stop"
    
        try
        {
            #
            # Deployment actions go here.
            #
        }
        catch
        {
            # Powershell tracks all Exceptions that occured so far in $Error
            Write-Output "$Error"
    
            # Signal failure to MSRM:
            $ErrorActionPreference = "Continue"
            Write-Error "Error: $Error"
        }
    }
    
    pushd $Global:ApplicationPath
    Deploy | Out-String | Write-Verbose -Verbose
    popd
    

    这只是最终结果,后面的解释可以找到here

    【讨论】:

      猜你喜欢
      • 2022-11-24
      • 2014-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-16
      • 2017-02-23
      • 1970-01-01
      • 2015-11-26
      相关资源
      最近更新 更多