带有参数的 Mac 上的 VSTS 运行 Powershell 脚本

VSTS Run Powershell Script on Mac with Parameters

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

我需要 运行 针对 Xamarin.iOS 使用本地 Mac 构建代理的相同 powershell 脚本。但是怎么办?

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

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

接下来,我通过稍微修改 .

提到的 shell 脚本,将参数传递给调用的 powershell 脚本
#!/bin/bash
powershell ./Version.ps1  

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

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

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