0

我有一个 Azure 发布管道,它调用阶段文件(yml),该文件又调用作业文件(yml),然后调用 powershell 脚本来执行。我很难弄清楚为什么参数没有传递到 powershell 脚本中。以下是我的阶段文件(仅发布部分不起作用的文件):

# Run Powershell to add A record
  - template: ../../Jobs/execute-azure-powershell.yml # name of job template to include
    parameters: # parameters needed by the template
      nicIdFromSqlJob: $[dependencies.Deploy_Managed_SQL.outputs['sqlserverdeploy.PvtendpointNicId']]
      vnetRg: "$(vnetRg)"
      deployment: 'Add_DNS_A_Record'
      displayName: 'Add DNS A record'
      pool: ${{ parameters.pool}}
      dependsOn: 'Deploy_Managed_SQL'
      condition: ''
      continueOnError: false
      variables: 
        nicIdFromSqlJobvar: ${{parameters.nicIdFromSqlJob}} 
      variablegroup: ${{ parameters.variablegroup}}
      environment: ${{ parameters.environment}}
      artifact: ${{ parameters.artifact}}
      azureResourceManagerConnection: ${{ parameters.azureResourceManagerConnection}}
      powershellFileScriptPath: '$(Pipeline.Workspace)/${{ parameters.artifact}}/Azure.Infra/Managed SQL/addDNSArecord.ps1'
      powershellScriptArguments: ''

上面的文件调用了execute-azure-powershell.yml,下面是代码:

用于 Azure Powershell 执行的 #Yaml 文件

parameters:
  deployment: ''
  displayName: ''
  pool: ''
  dependsOn: ''
  condition: ''
  continueOnError: ''
  variables: ''
  variablegroup: ''
  environment: ''
  artifact: ''
  azureResourceManagerConnection: ''
  powershellFileScriptPath: ''
  powershellScriptArguments: ''
  nicIdFromSqlJob: ''
  vnetRg: ''
  zoneName: 'privatelink.database.windows.net'

  
  
jobs:

- deployment: ${{ parameters.deployment}} # name of the deployment job, A-Z, a-z, 0-9, and underscore. The word "deploy" is a keyword and is unsupported as the deployment name.
  displayName: ${{ parameters.displayName}}  # friendly name to display in the UI
  pool: ${{ parameters.pool}} # The pool keyword specifies which pool to use for a job of the pipeline. A pool specification also holds information about the job's strategy for running.
  dependsOn: ${{ parameters.dependsOn}} # Job name that should be successfully done before this stage can run 
  condition: ${{ parameters.condition}} # Condition that needs to be fulfilled before the job can run 
  continueOnError: ${{ parameters.continueOnError}} # 'true' if future jobs should run even if this job fails; defaults to 'false'
  variables:
  - template: ${{ parameters.variables}} # name of variable template to include
  - group : ${{ parameters.variablegroup}} # name of a variable group

  
  environment: ${{ parameters.environment}} # target environment name and optionally a resource name to record the deployment history; format: <environment-name>.<resource-name>
  strategy:
      runOnce: #rolling, canary are the other strategies that are supported
        deploy:
          
          steps:
           
            - download: current
              artifact: ${{ parameters.artifact}}

            # Azure PowerShell
            # Run a PowerShell script within an Azure environment
            - task: AzurePowerShell@5
              displayName: 'Run Azure Powershell'
              inputs:
                azureSubscription:  ${{ parameters.azureResourceManagerConnection}} #Required. Name of Azure Resource Manager service connection
                scriptType: 'FilePath' # Optional. Options: filePath, inlineScript
                scriptPath: ${{ parameters.powershellFileScriptPath}} # Script File Path
                #inline: '# You can write your Azure PowerShell scripts inline here. # You can also pass predefined and custom variables to this script using arguments' # Optional
                arguments: 
                  -NicID ${{ parameters.nicIdFromSqlJob }}
                  -rgName ${{ parameters.vnetRg }}
                  -zoneName ${{ parameters.zoneName}}
                errorActionPreference: 'stop' # Optional. Options: stop, continue, silentlyContinue
                #failOnStandardError: false # Optional
                azurePowerShellVersion: 'latestVersion' # Required. Options: latestVersion, otherVersion
                #preferredAzurePowerShellVersion: # Required when azurePowerShellVersion == OtherVersion
                

以下是我的 addDNSArecord.ps1 文件:

param(
    $NicID,
    $rgName,
    $zoneName="privatelink.database.windows.net" 
)

$ip = Get-AzNetworkInterface -Id $NicID
$privateIPAddressPriout = $ip[0].IpConfigurations[0].PrivateIpAddress
$aRecordName = $ip[0].IpConfigurations[0].PrivateLinkConnectionProperties[0].Fqdns

Remove-AzPrivateDnsRecordSet -Name $aRecordName -ZoneName $zoneName -ResourceGroupName $rgName -Recordtype A -Confirm:$False -ErrorAction SilentlyContinue
 

New-AzPrivateDnsRecordSet -Name $aRecordName -RecordType A -ZoneName $zoneName `
  -ResourceGroupName $rgName -Ttl 3600 `
  -PrivateDnsRecords (New-AzPrivateDnsRecordConfig -IPv4Address $(privateIPAddressPriout))

每次我尝试运行管道时,我都会收到以下错误,现在我对传递参数的问题感到困惑,请对此提供任何帮助:message":"/Azure.Infra/Pipelines/Jobs/execute-azure- powershell.yml(第 77 行,第 34 列):意外符号:nicIdFromSqlJob}。位于表达式中的第 12 位:parameters.nicIdFromSqlJob}

4

0 回答 0