Home > OS >  Accessing secure file in Azure DevOps pipeline in PowerShell script
Accessing secure file in Azure DevOps pipeline in PowerShell script

Time:11-29

I am new to DevOps and trying to access the secure file via PowerShell script. Here is the scenario:

Agent I am using is ubuntu 18.04 I have uploaded my certificate as secure file and able to download when I am executing the pipeline. I have verified it by seeing the $(Agent.TempDirectory) content where certificate (.cer) is present.

Then I am running a PowerShell script which has below line of code:

$Certificate = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new('$(Agent.TempDirectory)/mycert.cer')

But this line always gives me the below error:

enter image description here

What is wrong here.

CodePudding user response:

The macro syntax $() will be expanded only in the template. If your script is stored in the file, you need to use environment variable: $env:AGENT_TEMPDIRECTORY

$Certificate = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new("$env:AGENT_TEMPDIRECTORY/mycert.cer")
  • Related