azure - 可以在 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
}
如何检查?
解决方案
更新:
根据您的评论,文件已存在于那里。此外,结合您的 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
}
推荐阅读
- c# - 每次我从矩形数组中删除一个项目时都会出现异常
- browser - 浏览器扩展可以访问我的脚本中的本地范围变量吗?
- .net - 构造函数中的这个参数如何直接在 FSharp 中的成员方法中使用?
- ruby - 有没有办法为 Chef 资源的 name 属性指定默认值?
- command - 将文件从 1 移动到不同的文件夹
- vba - MSAccess 2010 VBA 打开只读数据库
- r - inf_mr 不使用 xaringan 幻灯片刷新
- php - PHP Oracle 更新表错误 - oci_execute ORA-00933
- python - 无法连接到 Jupyter Notebook
- android - android分页如何刷新数据?