我正在尝试使用Azure DevOps中的Azure Powershell任务在Azure Keyvault中设置秘密。我使用以下代码:
Set-AzureKeyVaultSecret -VaultName $KeyvaultName -Name $SecretName -SecretValue $secretvalue
具有名称和值的所有变量都设置在变量内部,并尝试在不包含变量的情况下使用此变量。该值使用以下代码保存为安全字符串。ConvertTo-SecureString
但是当我在Azure DevOps Release管道中运行此powershell代码时,我不断收到以下错误消息:
Cannot retrieve access token for resource 'AzureKeyVaultServiceEndpointResourceId'. Please ensure that you have provided the appropriate access tokens when using access token login.
因此,我通过使用get,list,set secrets权限将它们都添加到访问策略中,从而确保了服务主体和构建服务器对密钥库具有正确的访问权限。
我还添加了以下代码行,以确保正确加载了配置文件
########################################################################################
$azureRmProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
$profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient -ArgumentList ($azureRmProfile)
$context = Get-AzureRmContext
$AzureToken = $profileClient.AcquireAccessToken($context.Tenant.Id)
Add-AzureRmAccount -AccessToken $AzureToken.AccessToken -AccountId $AzureToken.UserId
########################################################################################
通过在内联脚本的开头添加此代码,并将配置文件与突击队一起用作-DefaultProfile的变量。]>
是否有人也在尝试通过Azure DevOps中的powershell任务设置秘密。或者知道为什么Powershell脚本无法访问密钥库。azurermContext突击队为我提供了正确的输出,甚至尝试了Get-AzureRmKeyvault命令来确定与环境的连接是否已经正确建立。而且这也没有带来任何问题。
我正在尝试使用Azure DevOps中的Azure Powershell任务在Azure Keyvault中设置秘密。我使用以下代码:Set-AzureKeyVaultSecret -VaultName $ KeyvaultName -Name $ SecretName -...
确定工作之下(请定期使用)