大家
我的 DevOps 管道中有 2 个任务,第一个任务是从 Azure Key Vault 获取 secret 值,
trigger: none
jobs:
- job: PBICDSolution
pool:
vmImage: windows-latest
steps:
- checkout: self
- task: AzureKeyVault@2
inputs:
azureSubscription: '<my subscription>'
KeyVaultName: 'PA01'
SecretsFilter: '<my secret name>'
RunAsPreJob: false
接下来我想在我的 powershell 脚本中使用这个 secret 值来登录服务主体帐户。这是我的 powershell 代码,
$azureAplicationId = "<my service principal client id>"
$azureTenantId= "<my tanant id>"
Write-Output "Generate Credential"
$azurePassword = ConvertTo-SecureString <here should be the variable of AKV secret value> -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Write-Output "Login SP"
Connect-PowerBIServiceAccount -Tenant $azureTenantId -ServicePrincipal -Credential $psCred
这是上述任务的管道 yml 代码,
- task: AzurePowerShell@5
inputs:
azureSubscription: '<my subscripton name>'
ScriptType: 'FilePath'
ScriptPath: '$(Build.SourcesDirectory)\<my ps file name>.ps1'
ScriptArguments: '<how can i set the variable here?>'
azurePowerShellVersion: 'LatestVersion'
所以问题来了,如何从task1获取输出值,然后将该值传递给task2(PowerShell脚本)? 我引用过this docs但这没有帮助,因为我不需要将 secret 下载到 txt 文件。
任何解决方案将不胜感激!
最佳答案
how can I get the output value from task1, then pass this value into task2 (PowerShell script)?
您在 Azure Key Vault 任务中下载的 Key Vault 可以用作管道变量。
请参阅以下步骤来使用 Key Vault。
在 Azure Powershell 任务中,您可以定义参数:-azurePassword $(azurePassword)
例如:
- task: AzurePowerShell@5
displayName: 'Azure PowerShell script: FilePath'
inputs:
azureSubscription: xx
ScriptPath: test.ps1
ScriptArguments: '-azurePassword $(azurePassword)'
preferredAzurePowerShellVersion: 3.1.0
在Powershell文件中,您可以定义参数。
例如:
param (
[string]$azurePassword
)
关于powershell - 如何在 DevOps 管道上运行的 Powershell 上使用 key 保管库 secret ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71850843/