I solved the problem by adding the following task (in the yaml file) exactly before the task that need to use this link:
# 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"
This task will return a json object that contains the URL of the workflow (with some other stuff and details about this workflow) using cli commands (this cli command is working according to this issue). After getting this json $workflowDetails
, I assigen this parameter to a variable called WorkFlowDetails2
. WorkFlowDetails
can now be accessed in other tasks inside the SAME job (if you want to use it inside other jobs you need to make it as output parameter).
After thatyou can use this parameter normally in other task by calling something like: $(WorkFlowDetails)
So for e.g., if I need the workflow url to add it in namedValues in API management, I can have this task:
- 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"
My named value template now will looks something like:
{
"$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"
}
]
}