我如何检查一个工件是建立在ADO



我正在构建一个ADO管道,并希望在继续构建阶段之前检查是否已经创建了工件。我试图创建一个变量来告诉我文件是否存在,但当我运行管道时,我得到一个错误,说文件路径无效。

这是相关的代码:

- task: PublishBuildArtifacts@1
inputs: 
PathtoPublish: $(Build.ArtifactStagingDirectory) # dist or build files
ArtifactName: 'www' # output artifact named www

- task: PowerShell@2
inputs:
script: |
$fileExists = Test-Path -Path "$(Build.ArtifactStagingDirectory)/www/dist/apps/poc/index.html"
Write-Output "##vso[task.setvariable variable=FileExists]$fileExists"

- stage: deploy
condition: and(succeeded(), eq(variables['FileExists'], True))

这是我运行管道时得到的错误:

##[错误]文件路径'/home/vsts/work/1/s'无效。需要.ps1文件的路径。

##[error]文件路径'/home/vsts/work/1/s'无效。需要.ps1文件的路径。

在YAML示例中,如果使用内联脚本类型,则Powershell任务定义格式不正确。

需要定义targetType场。

例如:targetType: 'inline'

- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$fileExists = Test-Path -Path "$(Build.ArtifactStagingDirectory)/www/dist/apps/poc/index.html"

Write-Output "##vso[task.setvariable variable=FileExists]$fileExists"

最新更新