0

I am trying to download certificate file in azure pipelines. I have declared it as a download secureFile task in one of yaml files of my pipeline.

- task: DownloadSecureFile@1
name: certificateFileName
displayName: 'Download file Operation'
inputs:
  secureFile: mycert.crt

I also have another task which is the PowerShell script say Install.ps1. This script tries to import the certificate using Import-Certificate function.

Import-Certificate -FilePath "$(certificateFileName.secureFilePath)" -CertStoreLocation "Cert:\LocalMachine\Root"

I am getting an error as ObjectNotFound when trying to use $(certificateFileName.secureFilePath) within the function. I also tried using $(Agent.TempDirectory) to get the path of downloaded File as suggested by the Microsoft docs. This also results in ObjectNotFound error.

According to this stackoverflow link, it says that the path gets stored by default in $secureFilePath environment variable. I also tried to use this variable directly into my Import-Certificate function, but it seems the variable is empty.

What to do in this case? How do I check if download task is correctly downloading and storing the filepath? Just a sidenote, this pipeline also has a variables.yaml declared to define variables to be used across the entire pipeline tasks.

Dattebayo
  • 3
  • 2

1 Answers1

0

First help to confirm whether these two steps are in the same job of your Azure Pipeline.

If so, you could add a PowerShell task to check the file path of this secure file on the agent.

steps:
- task: DownloadSecureFile@1
  name: certificateFileName
  displayName: 'Download secure file'
  inputs:
    secureFile: 'mycert.crt'

- powershell: 'echo $(certificateFileName.secureFilePath)'
  displayName: 'PowerShell Script'

enter image description here

Kim Xu-MSFT
  • 1,819
  • 1
  • 2
  • 4
  • Hey @Kim Cu-MSFT yes these two steps are in the same job. I somehow believe that my Install powershell task is not getting my filepath. Is there anyway I can pass this variable $(certtificateFileName.secureFilePath) ? – Dattebayo Aug 08 '22 at 13:37