从连接到 Key vault 的 Azure DevOps 变量组访问证书指纹

Access certificate thumprint from Azure DevOps variable group connected to Key vaults

我有一个 VSTS 库变量组连接到我在 Azure 中的密钥库:

您可以在此处阅读更多相关信息: https://docs.microsoft.com/en-us/azure/devops/pipelines/library/variable-groups?view=vsts&tabs=yaml

在 Azure 的密钥保管库中,我有一个机密列表和证书列表。

密钥保管库机密示例:

示例证书:

现在我可以通过简单的语法访问作为变量释放这些变量:

我的目标是读取位于变量 $(GlobalCertificate) 中的证书指纹。获取途径是什么?

我知道这已经过时了,但我发现这篇文章在搜索相同的内容,但未能在其他地方找到解决方案。

我已经能够使用 Powershell 解决它,但考虑到我们已经将 PFX 上传到密钥库中,需要什么是奇怪的。我还将我的 pfx 密码保存到 keyvault 中,但如果你不这样做,请用你自己的值替换 $pwd 行中的变量。

在 Azure DevOps 管道中,创建一个 Powershell 任务。脚本是:

#Convert the Secure password that's presented as plain text back into a secure string
$pwd = ConvertTo-SecureString -String $(GlobalCertificate-Password) -Force -AsPlainText

#Create PFX file from Certificate Variable
New-Item Temp-Certificate.pfx -Value $(GlobalCertificate)

#Import the PFX certificate from the newly created file and password. Read the thumbprint into variable
$Thumbprint = (Import-PfxCertificate -CertStoreLocation Cert:\CurrentUser\My -FilePath Temp-Certificate.pfx -Password $pwd).Thumbprint

Write-Host $Thumbprint

#Rest of Script below or set environment variable for rest of Pipeline
Write-Host "##vso[task.setvariable variable=Thumbprint]$Thumbprint"