首页 > 解决方案 > 可以在 azure pipeline 中找到下载文件

问题描述

我正在尝试使用 azure 管道上传证书并绑定应用服务。首先我使用 DEV 阶段,一切正常。目前我必须为 QUAL env 创建一个新阶段。只需从 DEV 阶段克隆一个新阶段并更新变量,但我们运行管道找不到证书(文件) 我上传了。我的下载任务是:

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

然后使用 azure powershell 任务,但在我的脚本中会发生这样的错误:

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

似乎在代理中找不到下载文件。 在此处输入图像描述

上传任务:

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

电源外壳脚本:

$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
}

如何检查?

标签: azureazure-pipelinespipeline

解决方案


更新:

根据您的评论,文件已存在于那里。此外,结合您的 powershell 脚本和您的错误消息。

由于您只是共享 YAML 的一部分,我不知道您如何定义变量。请确保您的CertificateFileName变量已成功存储并传递给 powershell。

因为,完整的文件名应该显示在您的 powershell 错误消息中,即使它不存在于路径中。


实际上,更改使用的代理环境后很容易引起一些问题。

执行后Download secure file会生成一个环境变量,名称为secureFilePath. 您只需要 set is 作为输出变量并直接在您的 powershell 脚本中使用它。

YAML 和 powershell 脚本的小改动:

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

电源外壳:

$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
}

推荐阅读