簡體   English   中英

將 Terraform output 傳遞給 Powershell 任務在 Z3A580F142203677F1F0BC3089ZF8 中

[英]Passing Terraform output to Powershell task in Azure Devosps

在 Azure DevOps 中,我們有以下YAML管道,它從CmdLine任務應用 Terraform 配置。 Output 任務在Terraform部署后應返回Data Factory的 ObjectId。 我想使用該 ObjectId 並將其作為參數傳遞給下一個Azure Powershell Task ,以便我可以將該 ID 作為成員添加到 AzureADGroup。 如何在下一個Powershell任務中使用名為“Terraform 輸出”的步驟中的 output?

在此處輸入圖像描述

  - task: CmdLine@2
    displayName: Terraform Apply
    enabled: False
    inputs:
      script: terraform apply -auto-approve -input=false tfplan
      workingDirectory: infrastructure/tf_scripts/dev
  - task: CmdLine@2
    displayName: Terraform output
    enabled: False
    inputs:
      script: |
        terraform output adf_objectid
      workingDirectory: infrastructure/tf_scripts/dev

  - task: AzurePowerShell@4
    displayName: 'Azure PowerShell script: InlineScript'
    inputs:
      azureSubscription: 'a6cb1cd3-8d5e-4db6-8af5-bcb66492d5cc'
      ScriptType: 'InlineScript'
      Inline: |
                $spn=(terraform output adf_objectid)
                Connect-AzureAD -AadAccessToken $aadToken -AccountId $context.Account.Id -TenantId $context.tenant.id -MsAccessToken $graphToken
                Add-AzureADGroupMember -ObjectId xxxxx-xxxxx-xxxxx -RefObjectId $spn
      workingDirectory: wd/scripts/dev
      azurePowerShellVersion: 'LatestVersion'

將 Terraform output 傳遞給 Powershell 任務在 Z3A580F142203677F1F0BC3089ZF8 中

您可以嘗試使用日志記錄命令adf_objectid設置為 azure devops 管道變量:

echo ##vso[task.setvariable variable=spn]$(terraform output adf_objectid)

檢查類似的線程以獲取一些詳細信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM