可以在天蓝色的管道中找到下载文件

问题描述 投票:0回答:1

我正在尝试使用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/

似乎在代理中找不到下载文件。enter image description here

上传的任务:

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脚本:

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

如何检查?

azure azure-pipelines pipeline
1个回答
0
投票

已更新:

根据您的评论,文件已经存在。另外,将您的powershell脚本和错误消息结合在一起。

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

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


事实上,在更改所使用的代理环境之后,很容易引起某些问题。

执行Download secure file后,将生成一个名为secureFilePath的环境变量。您只需要将set作为输出变量,然后直接在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

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
}
© www.soinside.com 2019 - 2024. All rights reserved.