来自 teamcity 的 Azure 站点插槽交换
Azure site slot swap from teamcity
我有一个超级简单的脚本,用于交换 Azure 站点上的插槽。
它依赖于 azure 工具。
交换。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\workde96e708f2408e
[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,但我无法弄清楚为什么会这样(特别是考虑到它具有 azure 工具的输出,第 4,5 行)
我尝试过同时使用文件和源代码选项,结果相同。
知道为什么完全相同的脚本会 运行 在控制台中而不是在 teamcity 中吗?
所以我发现了问题,我不确定为什么它与 teamcity 隔离,但问题与此有关:
There is a known issue with PowerShell $env:PSModulePath that can
occur when installing from WebPI. If your computer requires a restart
due to system updates or other installations, it may cause updates
$env:PSModulePath to not include the path where Azure PowerShell is
installed. If this occurs, you may see a 'cmdlet not recognized'
message when attempting to use Azure PowerShell cmdlets after the
installation or upgrade. If this occurs, restarting the machine should
fix the problem.
https://azure.microsoft.com/en-us/documentation/articles/web-sites-staged-publishing/
当我重新启动 teamcity 机器时,一切正常。
我有一个超级简单的脚本,用于交换 Azure 站点上的插槽。
它依赖于 azure 工具。
交换。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\workde96e708f2408e
[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,但我无法弄清楚为什么会这样(特别是考虑到它具有 azure 工具的输出,第 4,5 行)
我尝试过同时使用文件和源代码选项,结果相同。
知道为什么完全相同的脚本会 运行 在控制台中而不是在 teamcity 中吗?
所以我发现了问题,我不确定为什么它与 teamcity 隔离,但问题与此有关:
There is a known issue with PowerShell $env:PSModulePath that can occur when installing from WebPI. If your computer requires a restart due to system updates or other installations, it may cause updates $env:PSModulePath to not include the path where Azure PowerShell is installed. If this occurs, you may see a 'cmdlet not recognized' message when attempting to use Azure PowerShell cmdlets after the installation or upgrade. If this occurs, restarting the machine should fix the problem.
https://azure.microsoft.com/en-us/documentation/articles/web-sites-staged-publishing/
当我重新启动 teamcity 机器时,一切正常。