来自teamcity的Azure站点插槽交换

时间:2016-07-14 10:16:10

标签: powershell azure teamcity

我有一个超级简单的脚本,应该在Azure中的站点上交换插槽。

它依赖于天蓝色的工具。

swap.ps1

& "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\ShortcutStartup.ps1"

Import-AzurePublishSettingsFile -PublishSettingsFile "mysubsettings.publishsettings"
Switch-AzureWebsiteSlot -Name "mysite" -Slot1 "staging" -Slot2 "production" -Force

如果我从控制台(powershell swap.ps1)执行此操作,一切都会完美无缺。

如果我在teamcity中执行此操作,我会得到:

[Step 1/1] PowerShell Executable: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
[10:05:45][Step 1/1] Working directory: C:\TeamCity\buildAgent\work\3de96e708f2408e
[10:05:45][Step 1/1] PowerShell arguments: [-NonInteractive, -ExecutionPolicy, ByPass, -File, swap.ps1]
[10:05:47][Step 1/1] For a list of all Azure cmdlets type 'get-help azure'.
[10:05:47][Step 1/1] For a list of Windows Azure Pack cmdlets type 'Get-Command *wapack*'.
[10:05:49][Step 1/1] Import-AzurePublishSettingsFile : The term 'Import-AzurePublishSettingsFile' 
[10:05:49][Step 1/1] is not recognized as the name of a cmdlet, function, script file, or operable 
[10:05:49][Step 1/1] program. Check the spelling of the name, or if a path was included, verify 
[10:05:49][Step 1/1] that the path is correct and try again.

它就像没有正确加载azure powershell但是我无法弄清楚为什么会这样(特别是考虑到它有天蓝色工具的输出,第4,5行)

我尝试过使用相同结果的文件和源代码选项。

为什么完全相同的脚本会在控制台中而不是在teamcity中运行的任何想法?

1 个答案:

答案 0 :(得分:1)

所以我发现了这个问题,我不知道为什么它被分离到团队城市,但问题与此有关:

  

PowerShell $ env:PSModulePath存在一个已知问题   从WebPI安装时发生。如果您的计算机需要重新启动   由于系统更新或其他安装,它可能会导致更新   $ env:PSModulePath不包括Azure PowerShell所在的路径   安装。如果发生这种情况,您可能会看到“cmdlet无法识别”   尝试使用Azure PowerShell cmdlet后出现错误消息   安装或升级。如果发生这种情况,应重新启动机器   解决问题。

https://azure.microsoft.com/en-us/documentation/articles/web-sites-staged-publishing/

当我重新启动teamcity机器时,一切正常。