Logic App Standard 自动引用跨环境的工作流

Logic App Standard Automate Reference to workflow accross environments

我已经使用 arm 模板通过 Azure Devops Pipeline 自动部署了逻辑应用程序标准

我有另一个管道使用 Azure Devops zip 部署任务 来部署工作流(按照 Microsoft 文档的建议)。

我目前的挣扎是当我有 调用其他工作流的工作流时 。 当我跨不同的逻辑应用程序标准实例部署 zip 文件时,引用的 工作流 url 始终相同 .

我怎样才能 reference/call 工作流以非硬编码的方式在部署中动态变化?我可以使用 workflow() 来引用其他工作流程吗?

由于访问密钥是工作流的 属性 而不是逻辑应用程序标准,因此我无法将其设置为要在工作流中使用的应用程序设置或参数。

关于如何绕过这个问题有什么想法吗?

我最后做了以下事情。 我已经创建了密钥保管库机密。在那些密钥保管库机密中,我存储了包含授权机密的工作流 url。

由于我创建了指向密钥保管库机密名称而不是硬编码 url 的其他工作流,逻辑应用程序在 运行 时将查询密钥保管库,检索 url 来自我想要验证身份并将其用作输入的工作流程。因为它已经包含签名,所以它可以正确验证。

这可能是一种解决方法,但这是我能够在此操作中取得成功的唯一方法。

对于和我有同样问题的人,这里是步骤:

  1. 首先,我开发了从密钥库
  2. 中获取包含 url 的秘密的工作流程

Get keyvault secret

  1. 然后它调用 url 使用秘密作为输入。 Secret as input for the url

  2. 当我的工作流准备好部署时。我导出它们并将代码放在 Azure Devops 上。

  3. 然后在构建管道中我使用以下任务

task: ArchiveFiles@2
displayName: "Archive Functions"
inputs:
rootFolderOrFile: "$(Build.Repository.LocalPath)/LogicApps"
includeRootFolder: false
archiveFile: "$(Build.ArtifactStagingDirectory)/LogicApps.zip"

task: AzureFunctionApp@1
displayName: "Deploy Functions"
inputs:
azureSubscription: "${ { parameters.Subscription }}"
appName: "mylogicappstandard"
package: "$(Agent.BuildDirectory)/${ { parameters.ArtifactName}}/LogicApps.zip"

task: AzureCLI@2
displayName: 'Update Signature url in ${ { parameters.KeyvaultName}}'
inputs:
azureSubscription: "${ { parameters.Subscription }}"
scriptType: 'ps'
scriptLocation: 'inlineScript'
inlineScript: "$(Agent.BuildDirectory)/${ { parameters.ArtifactName}}/Scripts/Get-WorkflowUrlSignature.ps1 $(AzureSubscriptionId) ${ { parameters.ResourceGroup }} mylogicappstandard ${ { parameters.KeyvaultName}}"

您可以在此处找到脚本的详细信息 Get-WorkflowUrlSignature。ps1

    [CmdletBinding()]
 param (
     [Parameter(Mandatory)][string]$SubscriptionId,
     [Parameter(Mandatory)][string]$ResourceGroup,
     [Parameter(Mandatory)][string]$LogicAppName,
     [Parameter(Mandatory)][string]$KeyVaultName
 )
    
 $json = az rest --method get --uri "https://management.azure.com/subscriptions/$SubscriptionId/resourceGroups/$ResourceGroup/providers/Microsoft.Web/sites/$LogicAppName/hostruntime/runtime/webhooks/workflow/api/management/workflows?api-version=2018-11-01"
 $workflows = $json | convertfrom-json
    
 foreach ($workflow in $workflows.Name){
     $uri ="https://management.azure.com/subscriptions/$SubscriptionId/resourceGroups/$ResourceGroup/providers/Microsoft.Web/sites/$LogicAppName/hostruntime/runtime/webhooks/workflow/api/management/workflows/$workflow/triggers/manual/listCallbackUrl?api-version=2018-11-01"
     if (az rest --method post --uri $uri){
         # Gets the url with signature
         $sigurl = az rest --method post --uri $uri | convertfrom-json
         $secret = $sigurl.value.Replace('&','"&"')
         $workflowName = $workflow.Replace("_","")
         #Creates or updates secret in the keyvault
         Write-Output "Updating secret $workflowName in the keyvault"
         az keyvault secret set --name $workflowName --vault-name $KeyVaultName --value $secret
     }else{
         Write-Output "The workflow $workflow does not have any trigger url"
     }
 }

我希望这可以帮助其他人自动化该过程。如果您有更简单的方法或查询访问密钥或 url 签名,请告诉我。