0

I uploaded a .cert certificate as secure file in azure devops

we are using Classic pipelines

my pipeline added two additional tasks

1, download secure file

2, Azure Cli task to import .cert file add below script as inline script

$certFilePath = $(Agent.TempDirectory)\mycert.com.crt az keyvault certificate import --vault-name "keyvaultname" -n "mycert.com.crt" -f $certFilePath

getting the below error

D:\agent_work_temp\mycert.com.crt : The term 'D:\agent_work_temp\mycert.com.crt' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At D:\agent_work_temp\azureclitaskscript1675572660483_inlinescript.ps1:1 char:12

  • $inFile = D:\agent_work_temp\mycert.com.crt
  •        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : ObjectNotFound: (D:\agent_work_temp\mycert.com.crt:String) [], ParentContainsErrorRe cordException
    • FullyQualifiedErrorId : CommandNotFoundException
ezycoder
  • 103
  • 2
  • 9

1 Answers1

0

I have tried to reproduce the same in my lab environment and got the below results.

Firstly, I would like to inform you that the file type of the certificate to be imported must be the .pfx or .pem extension. Kindly refer to this link for more details.

enter image description here

I have followed the below steps to upload a .pfx file to the Azure Key Vault.

Step 1: Created a .pfx type certificate.

Step 2: Upload a file to the secure files in Azure DevOps.

enter image description here

Step 3: Add below mentioned tasks to the pipeline.

enter image description here

enter image description here

Command: az keyvault certificate import --vault-name "key-vault-vijay" --file "$(Agent.TempDirectory)\test05.pfx" --name "cert0104" --password "passw0rd@123"

Pass the password parameter if you have created it at the time of certificate file creation.

Step 4: Verify the access policies assigned to the service principle using Azure DevOps automation on the key vault. enter image description here

Step 5: Run the pipeline and kindly check for the certificate on the Azure portal. enter image description here

enter image description here

Kindly refer to this link Manage Azure Key Vault using CLI - Azure Key Vault | Microsoft Learn for more details.

Sourav
  • 814
  • 1
  • 9