gpt4 book ai didi

azure - 无法在 Azure DevOps Pipeline 中找到为 ARM 模板部署创建的 JSON 文件路径

转载 作者:行者123 更新时间:2023-12-03 03:57:41 25 4
gpt4 key购买 nike

我正在尝试使用 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

有人可以帮忙吗?

最佳答案

您需要将 New-AzResourceGroupDeployment 中的 ' 单引号替换为双引号 "

在 PowerShell 中,双引号将允许您想要的字符串扩展,以便使用如下字符串扩展语法:

"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)

关于azure - 无法在 Azure DevOps Pipeline 中找到为 ARM 模板部署创建的 JSON 文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63905573/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com