Kevin YANG
Kevin YANG

Reputation: 441

Can find the download file in azure pipeline

I'm trying to use azure pipeline to upload certificate and binding the app service. First I use a DEV-stage,all works well.Currently I have to create a new stage for QUAL env.Just clone a new stage from DEV-stage and update the variables,but we run the pipeline can not find the certificate(file) I uploaded. My download task is:

steps:
- task: DownloadSecureFile@1
  displayName: 'Download ***.**.com Certificate for API App'
  inputs:
    secureFile: dev.pfx

and then use a azure powershell task,but in my script such error happens:

Certificate does not exist at path D:\a\_temp/

It seems can not find the download file in the agent. enter image description here

Uploaded task:

steps:
- task: AzurePowerShell@3
  displayName: 'Upload Certificate to API app and Bind Domain'
  inputs:
    azureSubscription: 'Azure: CDA NextGen DEV'
    ScriptPath: '$(System.DefaultWorkingDirectory)/CdaApi-ArmTemplates/ArmTemplates/InstallSSLAndCustomDomain.ps1'
    ScriptArguments: '-ResourceGroupName $(ResourceGroupName) -AppServiceName $(ApiSiteName) -CustomDomains $(ApiHostName) -CertificatePassword $(Password) -CertificateFileName $(CertificateFileName)'
    azurePowerShellVersion: LatestVersion

power shell script:

$CertificateFilePath = $env:AGENT_TEMPDIRECTORY + "/" +  $CertificateFileName

$ResourceGroupName -ResourceType Microsoft.Web/sites -ApiVersion 2014-11-01

if ([System.IO.File]::Exists($CertificateFilePath)) 
{
    Write-Host ("Certificate found at {0}" -f $CertificateFilePath)
}
else 
{
    Write-Error ("Certificate does not exist at path {0}" -f $CertificateFilePath)
    throw
}

How to check it?

Upvotes: 0

Views: 2052

Answers (1)

Mengdi Liang
Mengdi Liang

Reputation: 19026

Updated:

Based on your comment the files has been exists there. Also, combine your powershell script and your error message.

Since you just share the part of your YAML, I could not know how do you define variables. Please ensure your CertificateFileName variable has been stored and passed to powershell successfully.

Because, the complete file name should be displayed in your powershell error message even it does not exists in path.


In fact, it is very easy to cause some issue after you change the agent environment used.

After the Download secure file executed, it will generated one environment variable which name is secureFilePath. You just need set is as output variable and use it directly in your powershell script.

Little changes on your YAML and powershell script:

YAML:

steps:
- task: DownloadSecureFile@1
  displayName: 'Download ***.**.com Certificate for API App'
  inputs:
    secureFile: dev.pfx
  name: Path

- task: AzurePowerShell@3
  displayName: 'Upload Certificate to API app and Bind Domain'
  inputs:
    azureSubscription: 'Azure: CDA NextGen DEV'
    ScriptPath: '$(System.DefaultWorkingDirectory)/CdaApi-ArmTemplates/ArmTemplates/InstallSSLAndCustomDomain.ps1'
    ScriptArguments: '-ResourceGroupName $(ResourceGroupName) -AppServiceName $(ApiSiteName) -CustomDomains $(ApiHostName) -CertificatePassword $(Password) -CertificateFileName $(CertificateFileName) -SecureFilePath $(Path.secureFilePath)'
    azurePowerShellVersion: LatestVersion

Powershell:

$CertificateFilePath = $SecureFilePath

$ResourceGroupName -ResourceType Microsoft.Web/sites -ApiVersion 2014-11-01

if ([System.IO.File]::Exists($CertificateFilePath)) 
{
    Write-Host ("Certificate found at {0}" -f $CertificateFilePath)
}
else 
{
    Write-Error ("Certificate does not exist at path {0}" -f $CertificateFilePath)
    throw
}

Upvotes: 1

Related Questions