我通过在需要使用此链接的任务之前添加以下任务(在 yaml 文件中)解决了这个问题:
# getUrl
- task: AzureCLI@2
displayName: getLAUrl
name: getLAUrl
inputs:
azureSubscription: "${{ parameters.connectedServiceName }}"
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
$subscription = az account list --query "[?isDefault].id | [0]"
$ResourceGroupName = "${{ parameters.LA_rg }}"
$LogicAppName = "${{ parameters.LA_name }}-${{parameters.environment}}"
$MyWorkflow = "${{ parameters.LA_workflow }}"
$workflowDetails = az rest --method post --uri https://management.azure.com/subscriptions/$subscription/resourceGroups/$ResourceGroupName/providers/Microsoft.Web/sites/$LogicAppName/hostruntime/runtime/webhooks/workflow/api/management/workflows/$MyWorkflow/triggers/manual/listCallbackUrl?api-version=2018-11-01
# Write-Host "$workflowDetails"
echo "##vso[task.setvariable variable=WorkFlowDetails2]$workflowDetails"
此任务将使用 cli 命令返回一个 json 对象,其中包含工作流的 URL(以及有关此工作流的一些其他内容和详细信息)(此 cli 命令根据此问题工作)。得到这个 json 后$workflowDetails
,我将这个参数赋值给一个名为WorkFlowDetails2
. WorkFlowDetails
现在可以在 SAME 作业中的其他任务中访问(如果要在其他作业中使用它,则需要将其作为输出参数)。之后,您可以通过调用以下命令在其他任务中正常使用此参数:$(WorkFlowDetails)
因此,例如,如果我需要工作流 url 将其添加到 API 管理的 namedValues 中,我可以执行以下任务:
- task: AzureResourceManagerTemplateDeployment@3
displayName: DeployNamedValue
inputs:
deploymentScope: "Resource Group"
ConnectedServiceName: "${{ parameters.connectedServiceName }}"
action: "Create Or Update Resource Group"
resourceGroupName: "${{ parameters.resourceGroup }}"
location: ${{ parameters.location }}
templateLocation: "Linked artifact"
csmFile: '$(Pipeline.Workspace)/allApiArtifact/namedValues-template.json'
overrideParameters: '-LA_object_details $(WorkFlowDetails2) -LA_name ${{ parameters.LA_name }} -ApimServiceName ${{parameters.ApimServiceName}} -LA_workflow ${{parameters.LA_workflow}}'
deploymentMode: "Incremental"
我的命名值模板现在看起来像:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"ApimServiceName": {
"type": "string",
"defaultValue": "test"
},
"LA_name": {
"type": "string",
"defaultValue": "la_name"
},
"LA_workflow": {
"type": "string",
"defaultValue": "la_workflow"
},
"LA_object_details": {
"type": "object",
"defaultValue": {
"basePath": "",
"method": "",
"queries": {
"api-version": "",
"sig": "",
"sp": "",
"sv": ""
},
"value": ""
}
}
},
"variables":{
"la_version": "2020-05-01-preview",
"namedValue_prefix": "[split(parameters('LA_name'),'-')[0]]",
"namedValue_name": "[concat(variables('namedValue_prefix'), 'Url')]"
},
"resources": [
{
"properties": {
"tags": [],
"secret": true,
"displayName": "[variables('namedValue_name')]",
"value": "[concat('/api/', parameters('LA_workflow'), '/triggers/manual/invoke?api-version=', variables('la_version'), '&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=', parameters('LA_object_details').queries.sig)]"
},
"name": "[concat(parameters('ApimServiceName'), '/', variables('namedValue_name'))]",
"type": "Microsoft.ApiManagement/service/namedValues",
"apiVersion": "2021-01-01-preview"
}
]
}