【问题标题】:VSTS Run Powershell Script on Mac with ParametersVSTS 使用参数在 Mac 上运行 Powershell 脚本
【发布时间】:2017-11-14 07:41:48
【问题描述】:

我有一个 Xamarin.Forms 项目,其中 Android 项目是使用托管构建代理在 VSTS 中构建的,该代理在运行时运行一个 powershell 脚本。

我需要针对使用 On Premise Mac Build Agent 的 Xamarin.iOS 运行相同的 powershell 脚本。但是怎么做呢?

【问题讨论】:

    标签: powershell xamarin.ios azure-devops visual-studio-mac


    【解决方案1】:

    我发现这个answer 并且答案下的评论也有关于参数的相同问题,所以我在这里发布解决方案,因为问题略有不同并且该问题有一个可接受的答案。

    首先,我使用these instructions 在 Mac 上安装了 powershell,并修改了 shell 脚本任务以包含我想传递给 powershell 脚本的 Visual Studio Team Services (VSTS) 环境变量。

    接下来,我通过稍微修改referenced answer 提到的shell 脚本,将参数传递给调用的powershell 脚本。

    #!/bin/bash
    powershell ./Version.ps1 $1 $2
    

    最后,在 powershell 脚本中,我捕获了使用 using param 传递的参数,如下所示:

    param([string]$version, [string]$path)
    

    我现在可以使用变量 $version 和 $path 来满足我在 VSTS 中输入的原始参数来满足我的 powershell 脚本的需要。

    【讨论】:

    • 限制阻止了我在那天和后天这样做,然后我忘记了:P
    猜你喜欢
    • 2018-01-31
    • 2018-08-09
    • 1970-01-01
    • 1970-01-01
    • 2013-05-19
    • 2015-07-06
    • 1970-01-01
    • 2017-11-17
    • 2019-04-17
    相关资源
    最近更新 更多