Azure devops 将ip地址作为参数传递到python脚本模板

Azure devops 将ip地址作为参数传递到python脚本模板,azure-devops,Azure Devops,我有以下带有Azure DevOps管道模板的python脚本: # File: templates/clone-docker-volume.yml parameters: sourceVolume: '' targetVolume: '' pfaEndpoint: '' steps: - task: PythonScript@0 inputs: scriptSource: 'inline' script: | #!/usr/bin/env pyt

我有以下带有Azure DevOps管道模板的python脚本:

# File: templates/clone-docker-volume.yml

parameters:
  sourceVolume: ''
  targetVolume: ''
  pfaEndpoint: ''

steps:
- task: PythonScript@0
  inputs:
    scriptSource: 'inline'
    script: |
      #!/usr/bin/env python3
      import urllib3
      urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
      fa = myfunc(target="${{ parameters.pfaEndpoint }}")
当我在模板中硬编码对脚本的ip地址调用时,正如预期的那样工作,当我更改模板以使ip地址参数化时,我得到以下错误:

HTTPSConnectionPool(主机=“$(pfaendpoint)”,端口=443)

我在模板中调用脚本,如下所示:

- template: templates/python-template.yml  
    parameters:
      pfaEndpoint:  '$(pfaEndpoint)'

我怀疑这是导致脚本中使用的ip地址显示为“$(pfaEndpoint)”的问题。有人能告诉我如何解决这个问题,以便将ip地址正确地传递到模板中。

您只能使用该语法
${parameters.something}
如果它是一个“东西”,您不能将其嵌入字符串中。为此,您必须使用
格式
运算符:

script: |
  ${{ format('#!/usr/bin/env python3
      import urllib3
      urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
      fa = myfunc(target="{0}")', parameters.pfaEndpoint) }}
如果需要2个参数,请使用以下参数:

   ${{ format('{0} {1}', parameters.one, parameters.two) }}

如果myFunc接受多个参数,我是否会使用类似:fa=myFunc(target=“{0}”,parameters.pfaEndpoint,param2=“{0}”,parameters.param2)}}更新答案,就像您通常在c#more或lessThanks中使用格式运算符一样使用它来获取信息,这解决了我的问题,我已将其标记为答案。