Azure devops Azure Powershell-Az模块在Ubuntu托管的构建代理上不工作
我有一个运行在Azure DevOps中的构建,在Ubuntu 16.04托管的构建代理上。我正在使用最新版本的“Azure Powershell”任务(版本4.*预览),它应该是多平台的,支持Powershell核心,并支持使用 然而,这并不完全有效。在运行任何脚本之前,它会出现以下错误:Azure devops Azure Powershell-Az模块在Ubuntu托管的构建代理上不工作,azure-devops,azure-powershell,azure-devops-hosted-agent,Azure Devops,Azure Powershell,Azure Devops Hosted Agent,我有一个运行在Azure DevOps中的构建,在Ubuntu 16.04托管的构建代理上。我正在使用最新版本的“Azure Powershell”任务(版本4.*预览),它应该是多平台的,支持Powershell核心,并支持使用 然而,这并不完全有效。在运行任何脚本之前,它会出现以下错误: ##[section]Starting: Azure PowerShell script: InlineScript ===========================================
##[section]Starting: Azure PowerShell script: InlineScript
==============================================================================
Task : Azure PowerShell
Description : Run a PowerShell script within an Azure environment
Version : 4.0.0
Author : Microsoft Corporation
Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613749)
==============================================================================
##[warning]Can\'t find loc string for key: GeneratingScript
GeneratingScript
[command]/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command . '/home/vsts/work/_temp/e66222aa-283d-4dfd-b5c1-f1d2a4a3ba9f.ps1'
Could not find the module Az.Accounts with given version. If the module was recently installed, retry after restarting the Azure Pipelines task agent.
At /home/vsts/work/_tasks/AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62/4.0.0/InitializeAz.ps1:25 char:5
+ throw ("Could not find the module Az.Accounts with given version. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (Could not find ...nes task agent.:String) [], RuntimeException
+ FullyQualifiedErrorId : Could not find the module Az.Accounts with given version. If the module was recently installed, retry after restarting the Azure Pipelines task agent.
##[error]PowerShell exited with code '1'.
##[error]PowerShell wrote one or more lines to the standard error stream.
##[section]Finishing: Azure PowerShell script: InlineScript
Az Powershell模块似乎在Windows VS2017托管代理上正常工作/加载,但在Ubuntu上没有成功。有关于修复此问题的建议吗?通过添加先前的构建步骤,在构建代理上安装Az Powershell模块,我可以在Ubuntu代理上的Azure DevOps构建中使用Az Powershell 我添加了一个powershell脚本来安装Az模块并卸载Azure Rm模块;我从一个网站上调用它,这样我就可以把它包装在sudo中,让它成为一个全球性的变化 以下是命令行任务(YAML): 下面是
构建/安装az模块.ps1
脚本:
<#
.SYNOPSIS
Build agent script to install Az Powershell modules. This script should be run as sudo.
On a linux build agent, this command can be run as:
sudo /usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command . '$(Build.Repository.LocalPath)/build/install-az-modules.ps1'
#>
# Disable status info to clean up build agent stdout
$global:ProgressPreference = 'SilentlyContinue'
$global:VerbosePreference = "SilentlyContinue"
$azureRmModule = Get-InstalledModule AzureRM -ErrorAction SilentlyContinue
if ($azureRmModule) {
Write-Host 'AzureRM module exists. Removing it'
Uninstall-Module -Name AzureRM -AllVersions
Write-Host 'AzureRM module removed'
}
Write-Host 'Installing Az module...'
Install-Module Az -Force -AllowClobber
if (Get-Command Uninstall-AzureRm -ErrorAction SilentlyContinue) {
Write-Host 'Running Uninstall-AzureRm...'
Uninstall-AzureRm
}
#禁用状态信息以清除生成代理标准输出
$global:ProgressPreference='SilentlyContinue'
$global:VerbosePreference=“SilentlyContinue”
$AzureRM模块=获取安装模块AzureRM-ErrorAction SilentlyContinue
如果($azureRmModule){
写入主机“AzureRM模块存在。正在删除”
卸载模块-名称AzureRM-所有版本
写入主机“AzureRM模块已删除”
}
写入主机“安装Az模块…”
安装模块Az-Force-AllowClobber
if(Get命令Uninstall AzureRm-ErrorAction SilentlyContinue){
写入主机“正在运行卸载AzureRm…”
卸载AzureRm
}
相关,但与此特定问题无关(不使用Ubuntu)
<#
.SYNOPSIS
Build agent script to install Az Powershell modules. This script should be run as sudo.
On a linux build agent, this command can be run as:
sudo /usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command . '$(Build.Repository.LocalPath)/build/install-az-modules.ps1'
#>
# Disable status info to clean up build agent stdout
$global:ProgressPreference = 'SilentlyContinue'
$global:VerbosePreference = "SilentlyContinue"
$azureRmModule = Get-InstalledModule AzureRM -ErrorAction SilentlyContinue
if ($azureRmModule) {
Write-Host 'AzureRM module exists. Removing it'
Uninstall-Module -Name AzureRM -AllVersions
Write-Host 'AzureRM module removed'
}
Write-Host 'Installing Az module...'
Install-Module Az -Force -AllowClobber
if (Get-Command Uninstall-AzureRm -ErrorAction SilentlyContinue) {
Write-Host 'Running Uninstall-AzureRm...'
Uninstall-AzureRm
}