Azure Powershell-Az模块在Ubuntu托管的构建代理上不起作用 [英] Azure Powershell - Az module not working on Ubuntu hosted build agent
问题描述
我有一个在Ubuntu 16.04托管的生成代理上的Azure DevOps中运行的生成.我正在使用最新版本的"Azure Powershell"任务(4. *预览版),该任务应该是多平台的,支持Powershell核心,并支持使用
I have a build running in Azure DevOps, on an Ubuntu 16.04 hosted build agent. I'm using the latest version of the "Azure Powershell" task (version 4.* preview), which is supposed to be multi-platform, support Powershell core, and support using the Azure Powershell Az module.
但是,它并不完全有效.在运行我的任何脚本之前,它都会出现以下错误:
However, it doesn't quite work. Before running any of my script, it errors out with:
##[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上却没有运气.有任何解决此问题的建议吗?
The Az Powershell module appears to work/load correctly on the Windows VS2017 hosted agent, but no luck on Ubuntu. Any recommendations on fixing this?
推荐答案
通过在安装代理上安装Az Powershell模块的先前构建步骤,我能够使Az Powershell在Ubuntu代理上的Azure DevOps构建中工作.
I was able to get Az Powershell working in my Azure DevOps build on an Ubuntu agent by adding a prior build step that installs the Az Powershell module on the build agent.
我添加了一个powershell脚本来安装Az模块并卸载Azure-Rm模块;然后从命令行任务调用了它,因此我可以将其包装在sudo
使其成为全局更改.
I added a powershell script to install the Az module and uninstall the Azure-Rm module; and I called it from a command-line task so I could wrap it in sudo
to make it a global change.
这是命令行任务(YAML):
Here's the command-line task (YAML):
steps:
- displayName: 'Install Az Powershell Modules'
script: |
sudo /usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -File "$(Build.Repository.LocalPath)/build/install-az-modules.ps1"
这是build/install-az-modules.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
}
这篇关于Azure Powershell-Az模块在Ubuntu托管的构建代理上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!