簡體   English   中英

如何在 DevOps 發布管道中的 Azure Powershell 任務中使用環境變量?

[英]How can you use environment variables in an Azure Powershell task in a DevOps Release Pipeline?

在 Azure DevOps 發布管道中,我有一個代理工作。 在那個代理工作中,我有一個 Azure Powershell 任務。 我看不到為 Azure Z53301Z84AD41B22ACF367990701Z 任務運行的 Azure Powershell 腳本指定環境變量的方法。

您可以在構建管道中執行此操作,只需為 Azure PowerShell 任務指定“env”:

- task: AzurePowerShell@5
  inputs:
    azureSubscription: '...'
    ScriptType: 'FilePath'
    ScriptPath: '...'
    ScriptArguments: '...'
    FailOnStandardError: true
    azurePowerShellVersion: 'LatestVersion'
  env:
    USERNAME: $(username)
    PASSWORD: $(password)

但我看不到在發布管道中指定“env”的任何方式:

顯示無法添加環境變量的屏幕截圖

如何才能做到這一點?

當管道執行時,Azure 會將所有管道變量放入環境變量中,因此您作為構建的一部分運行的任何工具、腳本、任務或進程都可以通過環境訪問參數。

在 DevOps 管道 GUI 中定義變量:

在此處輸入圖像描述

要獲取 azure powershell 任務中的秘密變量,只需使用$(varibaleName)的語法即可。

我對發布管道中 powershell 腳本中的變量所做的事情是使用變量 Tab,您可以在其中添加變量對在管道變量中或在庫部分創建變量組,然后鏈接它。

因此,如果您為 compname computer1 創建一個變量對,那么在實際的 powershell 腳本中將該變量引用為 get-azvm -name $env:compname

這將提取您添加的變量

暫無
暫無

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

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