简体   繁体   English

在Mac上安装的VSTS代理中运行Powershell构建步骤?

[英]Run powershell build step in VSTS agent installed on mac?

I installed VSTS build agent on mac to build xamarin iOS project. 我在Mac上安装了VSTS构建代理,以构建xamarin iOS项目。 Builds worked fine until I added powershell build step. 在我添加powershell构建步骤之前,构建工作正常。 Even though I installed powershell for mac ( https://github.com/PowerShell/PowerShell ) and re-installed the agent, VSTS complains it does not have agent that is capable to run the build. 即使我为Mac安装了powershell( https://github.com/PowerShell/PowerShell )并重新安装了代理,VSTS仍抱怨它没有能够运行构建的代理。

No agent could be found with the following capabilities: DotNetFramework, Xamarin.iOS, npm 找不到具有以下功能的代理:DotNetFramework,Xamarin.iOS,npm

When I disable the build step, builds work just fine. 当我禁用构建步骤时,构建工作就可以了。

Is it possible to run powershell build step on Mac? 是否可以在Mac上运行Powershell构建步骤?

As MrHinsh clarified, the PowerShell task cannot be used on Mac. 正如MrHinsh所阐明的那样,PowerShell任务不能在Mac上使用。

As a workaround I used ShellScript task: 解决方法是使用ShellScript任务:

ShellScript任务

With the following bash script: 使用以下bash脚本:

#!/bin/bash
powershell ./SetAppVersion.ps1

Also, the powershell installer did not seem to add powershell to my PATH so I had to add it: 另外,powershell安装程序似乎没有将powershell添加到我的PATH中,因此我不得不添加它:

$ export PATH=$PATH:/usr/local/microsoft/powershell/6.0.0-alpha.16

If you're sure that DotNetFramework is installed then you can go to the Agent Queues settings and add a custom Capability to it called exactly that. 如果确定已安装DotNetFramework,则可以转到“代理队列”设置,并为其添加自定义功能,即所谓的功能。

That should allow it to run but it might fail after that if the agent can't actually find them, but it might also succeed so it's probably worth a try. 那应该允许它运行,但是如果代理无法实际找到它们,则此后可能会失败,但是它也可能成功,因此值得尝试。

No, you can't use a PowerShell task on a Mac, only node tasks are supported. 不,您不能在Mac上使用PowerShell任务,仅支持节点任务。

PowerShell tasks as currently written in PowerShell3 which is not supported on Mac. 当前在PowerShell3中编写的PowerShell任务,Mac上不支持。 You can request that the team implement this on http://visualstudio.uservoice.com 您可以在http://visualstudio.uservoice.com上要求团队实施此操作

In TFS build go to Agents Queues=>Capablilities=>Add variable named as DotNetFramework and give value for mac agent's dotnet framework path. 在TFS构建中,转到Agents Queues => Capablilities =>添加名为DotNetFramework的变量,并为mac agent的dotnet框架路径提供值。

在此处输入图片说明 It's fix for the issue "No agent could be found with the following capabilities:DotNetFramework " 解决了“找不到具有以下功能的代理:DotNetFramework ”的问题

This is a follow-up to the accepted answer to address a question in a comment which I also had. 这是在我也有评论中解决问题的已接受答案的跟进。

Thanks to spatialguy for posting and finding a simple solution to this problem. 感谢spatialguy发布并找到此问题的简单解决方案。 I had the same problem as KeithA45 : 我有与KeithA45相同的问题:

QUESTION: What if you wanted to do the same, but also pass arguments to the Bash script which passes them to the Powershell script? 问题:如果您想做同样的事情,但又将参数传递给Bash脚本,然后又将参数传递给Powershell脚本,该怎么办?

I found a solution to this, first off, I modified the shell script task to include the Visual Studio Team Services (VSTS) environmental variables that I wanted to pass to the powershell script. 我找到了解决方案,首先,我修改了外壳脚本任务,以包含要传递给powershell脚本的Visual Studio Team Services(VSTS)环境变量。

在此处输入图片说明

Next, I pass the arguments through to the called powershell script by slightly modifying the shell script mentioned by the accepted answer . 接下来,我通过稍微修改已接受的answer所提到的shell脚本,将参数传递给被调用的powershell脚本。

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

Finally, in the powershell script, I catch the arguments that have been passed through using using param like this: 最后,在powershell脚本中,我使用如下param捕获通过传递的参数:

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

Wherein I can now use the variables $version and $path which contain the original arguments entered in VSTS to the needs of my powershell script. 现在,我可以使用变量$ version和$ path,这些变量包含在VSTS中输入的原始参数以满足我的powershell脚本的需要。

Things seem to have moved forward because I ran successfully today a PowerShell@2 task on a Mac Self-Hosted Agent from an Azure DevOps build pipeline. 事情似乎已经向前发展,因为今天我从Azure DevOps构建管道成功地在Mac自托管代理上运行了PowerShell@2任务。

By checking "Enable system diagnostics" when queuing the build, the log shows me that the task found itself the path to the PowerShell Core (pwsh) that I installed on my Mac with the help of Homebrew ( brew cask install powershell - see https://docs.microsoft.com/fr-fr/powershell/scripting/install/installing-powershell-core-on-macos ). 通过在使构建排队时检查“启用系统诊断”,日志向我显示该任务本身找到了在Homebrew的帮助下在Mac上安装的PowerShell Core(pwsh)的路径(brew cask brew cask install powershell请参阅https: //docs.microsoft.com/fr-fr/powershell/scripting/install/installing-powershell-core-on-macos )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 VSTS在Mac上使用参数运行Powershell脚本 - VSTS Run Powershell Script on Mac with Parameters 由Powershell的VSTS代理运行的Excel由于未知原因而失败 - Excel run by VSTS agent from Powershell fails for unknown reason 使用Powershell查找从SQL代理作业运行的最后一步 - Using Powershell to find last step run from an SQL agent job 无法在 SQL 服务器代理作业步骤中运行 Powershell 命令 - Can't run a Powershell command in a SQL Server Agent Job Step 来自 VSTS 构建步骤的 Powershell Invoke-RestMethod 失败并出现错误 417 - Powershell Invoke-RestMethod from VSTS build step fails with error 417 如何使用 PowerShell 监控 VSTS 代理的可用性? - How to monitor VSTS agent availability using PowerShell? VSTS Build和PowerShell和AzureAD身份验证 - VSTS Build and PowerShell and AzureAD Authentication 将Powershell脚本作为VSTS中的任务运行 - run a powershell script as a task in VSTS 如何在VSTS中的托管代理上运行或安装工具 - How to run or install tool on hosted agent in VSTS 如何从Azure Powershell中的VSTS构建并行运行Start-AzureVM? - How to run Start-AzureVM in parallel from a VSTS Build in Azure Powershell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM