我必须在脚本内使用不同的参数多次执行命令。有没有更好的方法而不是复制粘贴相同的命令并更改参数?
- job: Configure_in_QA
variables:
- group: development
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Cache@2
inputs:
key: piper-go-official
path: bin
displayName: Configure_Iflow_in_QA
- script: |
bin/piper integrationArtifactUpdateConfiguration --verbose true --apiServiceKey $(CREDENTIALS) --integrationFlowId "Test_IFlow1_QA" --integrationFlowVersion 'Active' --Key 'LogEnabled' --Value 'true'
bin/piper integrationArtifactUpdateConfiguration --verbose true --apiServiceKey $(CREDENTIALS) --integrationFlowId "Test_IFlow1_QA" --integrationFlowVersion 'Active' --Key 'SNDPRN' --Value '1010101'
有没有比复制粘贴相同命令并更改参数更好的方法?
我建议你可以在Pipeline中定义一个对象类型参数,然后使用each表达式循环参数中的对象来运行脚本任务。
这是一个例子:
parameters:
- name: valuelist
type: object
default:
- key: LogEnabled
value: true
- key: SNDPRN
Value : 1010101
jobs:
- job: Configure_in_QA
variables:
- group: development
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Cache@2
inputs:
key: piper-go-official
path: bin
displayName: Configure_Iflow_in_QA
- ${{ each value in parameters.valuelist }}:
- script: |
bin/piper integrationArtifactUpdateConfiguration --verbose true --apiServiceKey $(CREDENTIALS) --integrationFlowId "Test_IFlow1_QA" --integrationFlowVersion 'Active' --Key '${{value.key}}' --Value '${{value.value}}'
它会根据参数中取值的个数,运行相应次数的脚本任务,并传递相应的参数值。