【问题标题】:What datatype of parameters can be used for IP address in Azure Devops pipeline?Azure Devops 管道中的 IP 地址可以使用哪些数据类型的参数?
【发布时间】:2021-11-14 18:19:38
【问题描述】:

为了向 azurepipeline yaml 传递值,在运行时,我一直在寻找合适的参数数据类型来传递 ip 地址。这可以作为字符串添加吗?

parameters:
- name: subscription
  type: string
  default: 'Mysubscription'
- name: DZoneResourcegroup
  type: string
  default: ''
- name: DZone
  type: string
  default: ''
- name: hostname
  type: string
  default: ''
- name: ip
  type: string
  default: ''  


    
trigger: none

stages:
- stage: Create_DNS_Record
  displayName: 'Create DNS Record'
  jobs:
  - job: Create_DNS
    pool:
      name: mypool   
    steps:
    - task: AzureCLI@2
      inputs:
        azureSubscription: ${{ parameters.subscription }}
        scriptType: 'bash'
        scriptLocation: 'inlineScript'
        inlineScript: 'az network dns record-set a add-record -g ${{ parameters.DZoneResourcegroup }} -z ${{ parameters.DZone }} -n ${{ parameters.hostname }}  -a ${{ parameters.ip }}'

如果可能的话,还要寻找比这更好的方法来实现自动化,并在相应的记录已存在于 DNS 区域中时收到通知。

【问题讨论】:

    标签: azure-devops azure-pipelines azure-cli


    【解决方案1】:

    是的,您应该使用 string 作为参数的数据类型来传递 IP 地址。即使您检查了 az network dns record-set 命令的 required parameter 部分,您也会发现它接受字符串表示法的 IPv4 地址。

    您还可以修改管道中的流程。您应该运行多行脚本,而不是运行内联脚本,您可以在其中使用az network dns record-set <record-type> show 命令检索现有记录集,然后运行条件语句以在创建之前检查相应记录是否已经存在。

    以下示例从资源组 MyRG

    az network dns record-set a show --resource-group myRG --zone-name abc.com --name www
    

    我建议阅读此Manage DNS records and recordsets in Azure DNS using the Azure CLI 文档以获取更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-09
      • 1970-01-01
      • 2020-10-30
      • 1970-01-01
      • 1970-01-01
      • 2020-01-15
      • 2011-07-05
      • 2020-11-09
      相关资源
      最近更新 更多