仅当 Azure 管道中存在时才下载并发布工件

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

使用azure pipeline的任务是否可以仅在存在的情况下下载和发布工件?

-> 我的第一个任务是构建 - 但该构建有点特殊,它将检查自上次提交以来是否有更改。如果没有任何改变,就不会构建任何东西。

-> 第二个任务是下载神器,但是在没有构建任何内容的情况下,将没有任何内容可下载。

因为构建没有创建任何文件夹,所以我的 CI 失败了。

有没有办法“告诉”下载任务:“仅在存在时下载”。 或者仅当创建的文件夹完成时才继续执行任务 3。

谢谢你

azure-devops azure-pipelines
3个回答
4
投票

您可以为此目的使用变量,并根据您是否要创建工件的事实动态设置它们

  steps:
  - bash: |
      echo "Test here if you have folder which will you use to create an artifact and then set Yes or No"
      echo "##vso[task.setvariable variable=doThing]Yes" #set variable doThing to Yes
    name: DetermineResult
  - script: echo "Job Foo ran and doThing is Yes."
    condition: eq(variables['doThing'], 'Yes')
  - script: echo "Skip this one"
    condition: ne(variables['doThing'], 'Yes')

4
投票

根据您的需求,您可以在下载工件任务之前添加一个任务来判断是否存在文件夹,然后决定是否运行下载工件任务。

以下是示例:

检查文件夹是否存在:

steps:

- powershell: |
   $Folder = '$(Build.ArtifactStagingDirectory)'
   "Test to see if folder [$Folder]  exists"
   if (Test-Path -Path $Folder) {
     echo "##vso[task.setvariable variable=test]Yes"
   } else {
        echo "##vso[task.setvariable variable=test]No"
   }
  displayName: 'PowerShell Script'


- task: DownloadBuildArtifacts@1
  displayName: 'Download Build Artifacts'
  inputs:
    downloadType: specific
  condition: ne(variables['test'], 'Yes')

检查文件夹是否为空:

steps:
- powershell: |
   $directoryInfo = Get-ChildItem $(Build.ArtifactStagingDirectory) | Measure-Object
   $directoryInfo.count
   echo  $directoryInfo.count
   
   if ( $directoryInfo.count -eq 0 ) 
   {
     echo "##vso[task.setvariable variable=test]Yes"
      
   }
   else
   
   {
     echo "##vso[task.setvariable variable=test]No"
     
   }
   
   
  displayName: 'PowerShell Script'



- task: DownloadBuildArtifacts@1
  displayName: 'Download Build Artifacts'
  inputs:
    downloadType: specific
  condition: ne(variables['test'], 'Yes')

0
投票

没有,但你可以添加

continueOnError: true

转到您的下载任务以继续运行作业,然后测试脚本中是否存在工件文件夹

© www.soinside.com 2019 - 2024. All rights reserved.