我正在尝试使用自动部署中的管道运行 SQL 脚本,以使用以下 YML 文件进行数据库更改。但我收到以下错误消息。
trigger:
- main
pool:
vmImage: windows-2022
variables:
AzureSubscription: 'XXX'
ResourceGroupName: 'XXX'
ResourceDBGroupName: 'XXX'
ServerName: 'XXX'
DatabaseName: 'XXX'
AdminUser: 'XXX'
AdminPassword: 'XXX'
SQLFile: 'DatabasePipelineTest/scripts/script.sql'
AzureFirewallName: 'allow-pipe'
steps:
- script: dir
displayName: 'Run a one-line script to test'
- task: AzurePowerShell@2
displayName: Azure PowerShell
inputs:
azureSubscription: '$(AzureSubscription)'
ScriptPath: '$(Build.SourcesDirectory)/DatabasePipelineTest/scripts/SetAzureFirewallRule.ps1'
ScriptArguments: '-ServerName $(ServerName) -ResourceGroupName $(ResourceDBGroupName) -AzureFirewallName $(AzureFirewallName)'
azurePowerShellVersion: LatestVersion
- task: CmdLine@1
displayName: Run Sqlcmd
inputs:
filename: Sqlcmd
arguments: '-S $(ServerName) -U $(AdminUser) -P $(AdminPassword) -d $(DatabaseName) -i $(SQLFile)'
- task: AzurePowerShell@5
displayName: Azure PowerShell
inputs:
azureSubscription: '$(AzureSubscription)'
ScriptPath: '$(Build.SourcesDirectory)/DatabasePipelineTest/scripts/RemoveAzureFirewallRule.ps1'
ScriptArguments: '$(ServerName)'
azurePowerShellVersion: LatestVersion
我在控制台中得到的输出如下,
Azure PowerShell
View raw log
Starting: Azure PowerShell
==============================================================================
Task : Azure PowerShell
Description : Run a PowerShell script within an Azure environment
Version : 2.198.0
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-powershell
==============================================================================
Added TLS 1.2 in session.
Import-Module -Name C:\Modules\azurerm_6.13.1\AzureRM\6.13.1\AzureRM.psd1 -Global
Clear-AzureRmContext -Scope Process
Disable-AzureRmContextAutosave -ErrorAction Stop
Disconnect-AzureRmAccount -Scope Process -ErrorAction Stop
Clear-AzureRmContext -Scope Process -ErrorAction Stop
##[error]The term 'New-AzSqlServerFirewallRule' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Finishing: Azure PowerShell
有问题的脚本如下
[CmdletBinding(DefaultParameterSetName = 'None')]
param
(
[String] [Parameter(Mandatory = $true)] $ServerName,
[String] [Parameter(Mandatory = $true)] $ResourceGroupName,
[String] [Parameter(Mandatory = $true)] $AzureFirewallName
)
$agentIP = (New-Object net.webclient).downloadstring("https://api.ipify.org")
New-AzSqlServerFirewallRule -ResourceGroupName $ResourceGroupName -ServerName $ServerName -FirewallRuleName $AzureFirewallName -StartIPAddress $agentIp -EndIPAddress $agentIP
最佳答案
如果您指定了任务版本,是否可以 checkin DevOps 任务:4。 (预览) 或更高版本以使用 Az powershell 模块
关于azure - 无法识别“New-AzSqlServerFirewallRule” - Azure Dev Ops Pipeline 的 Azure PowerShell 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71446862/