azure-devops - Azure devops pfx 安装在远程虚拟机中
问题描述
我正在尝试在我的 azure vm 中安装 pfx 证书并将我的 pfx 文件保存在变量组中并保存了我的 pfx 密码。我正在使用下面的 yaml 脚本进行部署,但它不起作用。我的天蓝色远程虚拟机中没有安装证书。
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
- group: certificate-variable
steps:
- task: DownloadSecureFile@1
name: mySecureFile
displayName: 'Get the pfx file certificat'
inputs:
secureFile: '$(signingCert.secureFilePath)'
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
Write-Host "Start adding the PFX file to the certificate store."
$pfxpath = '$(mySecureFile.secureFilePath)'
$password = '$(signingCert.password)'
Add-Type -AssemblyName System.Security
$cert =New-Object -TypeName
System.Security.Cryptography.X509Certificates.X509Certificate2($pfxpath, $password,
[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]PersistKeySet)
$store =New-object system.security.cryptography.X509Certificates.X509Store,CurrentUser
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]ReadWrite)
$store.Add($cert)
$store.Close()
解决方案
你可以试试这个power shell脚本
$pfxpath = '$(mySecureFile.secureFilePath)'
$password = '$(signingCert.password)'
Add-Type -AssemblyName System.Security
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$cert.Import($pfxpath, $password, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]"PersistKeySet")
$store = new-object system.security.cryptography.X509Certificates.X509Store -argumentlist "MY", CurrentUser
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]"ReadWrite")
$store.Add($cert)
$store.Close()
此外,我们可以创建一个变量组并添加一个名为 sSecStrPassword 的变量来保存密码,并添加 power shell 脚本以将构建管道上使用的 .pfx 证书与下载安全文件任务一起使用。您可以参考此答案以获取更多详细信息。
推荐阅读
- binary - 使用 cygwin 的网络模拟器 2(ns2)给出错误:“无法在 cygwin 中执行二进制文件 exec 格式错误”
- android - Android:结合同一个库的不同版本,一个是旧的,一个是在一个项目中迁移的
- android - Android 测试应用程序向后执行编程步骤
- nuxt.js - Nuxt 嵌套 url 目录
- kotlin - 如何在 Kotlin 中使用 _Assertions 对象?
- java - 一个数字出现多少次
- python - 使用 Python Whoosh 进行模糊搜索(排名/分数直接命中高于模糊命中)
- php - php中的数组推送和合并
- python - 放大推送时出现“创建虚拟环境失败”错误
- dns - 非常简单的bind9 DNS服务器