在为 ARM 模板部署创建的 Azure DevOps Pipeline 中找不到 JSON 文件路径
Posted
技术标签:
【中文标题】在为 ARM 模板部署创建的 Azure DevOps Pipeline 中找不到 JSON 文件路径【英文标题】:Unable to find the JSON file path in Azure DevOps Pipeline which is created for ARM template deployment 【发布时间】:2021-01-02 10:20:30 【问题描述】:我正在尝试使用 Azure PowerShell Pipeline 使用 ARM 模板创建 Azure 资源。
我的两个 ARM 模板 JSON 文件存放在 YAML 文件和 Powershell 文件存放的同一目录中
这是Powershell文件的代码
param (
#Name of the Resource Group of the Image Gallery
[Parameter(Mandatory=$true)]
[string]
$deploymentName,
#Name of the Image Gallery
[Parameter(Mandatory=$true)]
[string]
$rgName
)
New-AzResourceGroupDeployment -Name $deploymentName -ResourceGroupName $rgName `
-TemplateFile '$(System.DefaultWorkingDirectory)/Deploy.json' `
-TemplateParameterFile '$(System.DefaultWorkingDirectory)/DeployParameters.json'
这是 YAML 文件的代码
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger: none
pool: 'Default'
#vmImage: 'ubuntu-latest'
steps:
- script: echo Create, Shared Image Gallery!
displayName: 'Run a multiline-line script'
- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
displayName: 'Run a multi-line script'
- task: AzurePowerShell@5
inputs:
azureSubscription: 'Visual Studio Enterprise Subscription – MPN(08f41212-2053-434e-b4b3-ace08XXXXXX)'
ScriptType: 'FilePath'
ScriptPath: '$(System.DefaultWorkingDirectory)/Deploy_New.ps1'
ScriptArguments: -deploymentName "WVD" -rgName "WVDRG"
azurePowerShellVersion: LatestVersion
pwsh: true
这是我遇到的错误,我正在使用在 Windows Server 2019 和 PowerShell Core 中运行的自托管代理池。
020-09-15T15:41:38.8359249Z ##[section]Starting: AzurePowerShell
2020-09-15T15:41:38.8615322Z ==============================================================================
2020-09-15T15:41:38.8615818Z Task : Azure PowerShell
2020-09-15T15:41:38.8616217Z Description : Run a PowerShell script within an Azure environment
2020-09-15T15:41:38.8616582Z Version : 5.173.1
2020-09-15T15:41:38.8616919Z Author : Microsoft Corporation
2020-09-15T15:41:38.8617547Z Help : https://aka.ms/azurepowershelltroubleshooting
2020-09-15T15:41:38.8617935Z ==============================================================================
2020-09-15T15:41:40.0811736Z Generating script.
2020-09-15T15:41:40.1352322Z ========================== Starting Command Output ===========================
2020-09-15T15:41:40.1634699Z ##[command]"C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'C:\agent\_work\_temp\1d73a74d-12ca-470b-bd53-c23358ee4e2d.ps1'"
2020-09-15T15:41:41.5971906Z Added TLS 1.2 in session.
2020-09-15T15:41:41.7815293Z ##[command]Import-Module -Name C:\Program Files\PowerShell\Modules\Az.Accounts\1.9.3\Az.Accounts.psd1 -Global
2020-09-15T15:41:42.3907347Z ##[command]Clear-AzContext -Scope Process
2020-09-15T15:41:42.7014316Z ##[command]Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
2020-09-15T15:41:43.3364066Z ##[command]Connect-AzAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
2020-09-15T15:41:45.2061727Z ##[command] Set-AzContext -SubscriptionId 08f41212-2053-434e-b4b3-XXXXX -TenantId ***
2020-09-15T15:41:47.5198572Z ##[error]Cannot retrieve the dynamic parameters for the cmdlet. Cannot find path 'C:\agent\_work\3\s\$(System.DefaultWorkingDirectory)\DeployHostPool.json' because it does not exist.
2020-09-15T15:41:47.6342141Z ##[error]PowerShell exited with code '1'.
2020-09-15T15:41:48.1235457Z ##[section]Finishing: AzurePowerShell
有人可以帮忙吗?
【问题讨论】:
【参考方案1】:您需要将那些 '
单引号换成双引号,"
中的 New-AzResourceGroupDeployment
。
在 PowerShell 中,双引号将允许 String Expansion
这是您想要的,以便使用这样的字符串扩展语法:
"This computer is called $($env:COMPUTERNAME)"
PS>This computer is called eLope
当你使用单引号时,它总是会给你一个字符串文字,像这样:
'This computer is called $($env:COMPUTERNAME)'
PS>This computer is called $($env:COMPUTERNAME)
【讨论】:
它就像一个冠军,感谢您的快速回复。你有美好的一天。以上是关于在为 ARM 模板部署创建的 Azure DevOps Pipeline 中找不到 JSON 文件路径的主要内容,如果未能解决你的问题,请参考以下文章
Azure,java sdk,使用ARM模板部署 - 无法转换参数文件