Skip to content

Replace DownloadPipelineArtifact by a pipeline step #7021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .azure-pipelines/steps/download-artifact.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# .azure-pipelines/steps/download-artifact.yml
parameters:
artifact: ''
path: ''
patterns: ''
condition: ''
# Defaults
timeoutInMinutes: 10
retryCountOnTaskFailure: 3

steps:
- task: DownloadPipelineArtifact@2
displayName: "Download ${{ parameters.artifact }}"
condition: ${{ parameters.condition }}
timeoutInMinutes: ${{ parameters.timeoutInMinutes }}
retryCountOnTaskFailure: ${{ parameters.retryCountOnTaskFailure }}
inputs:
artifact: ${{ parameters.artifact }}
path: ${{ parameters.path }}
patterns: ${{ parameters.patterns }}
Copy link
Contributor Author

@NachoEchevarria NachoEchevarria May 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this adds a global timeout and retry values, the task would fail if a single download task takes more than 45 minutes. The ideal solution would be to set a global timeout and cancel a particular download task after something like 20 mins and retry. Doing that would not be very straightforward, but we could do something like this. Still, pretty ugly.

parameters:
  artifact: ''
  path: ''
  patterns: ''
  displayName: ''
  condition: ''
  timeoutInMinutes: 45
  retryCountOnTaskFailure: 3

steps:
- bash: |
    max_retries=${{ parameters.retryCountOnTaskFailure }}
    attempt=1
    end=$((SECONDS + ${{ parameters.timeoutInMinutes }} * 60))

    while [ $attempt -le $max_retries ] && [ $SECONDS -lt $end ]; do
      echo "Attempt $attempt of $max_retries..."

      timeout 1200 az pipelines runs artifact download \
        --artifact-name "${{ parameters.artifact }}" \
        --path "${{ parameters.path }}" \
        --patterns "${{ parameters.patterns }}"
      
      exit_code=$?
      if [ $exit_code -eq 0 ]; then
        echo "Artifact download successful on attempt $attempt."
        exit 0
      else
        echo "Attempt $attempt failed (exit code $exit_code)."
        if [ $attempt -lt $max_retries ]; then
          echo "Retrying after short delay..."
          sleep 30
        fi
      fi

      attempt=$((attempt + 1))
    done

    echo "All attempts failed or global timeout exceeded."
    exit 1
  displayName: ${{ parameters.displayName }}
  condition: ${{ parameters.condition }}
  timeoutInMinutes: ${{ parameters.timeoutInMinutes }}

13 changes: 5 additions & 8 deletions .azure-pipelines/steps/download-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ parameters:
default: ''

steps:
- task: DownloadPipelineArtifact@2
displayName: Download standalone samples
inputs:
- template: download-artifact.yml
parameters:
artifact: samples-standalone
path: $(outputDir)/bin
retryCountOnTaskFailure: 5

- ${{ if ne(parameters.framework, '') }}:
- task: DownloadPipelineArtifact@2
displayName: Download multi-version samples
inputs:
- template: download-artifact.yml
parameters:
artifact: samples-multi-version-${{ parameters.framework }}
path: $(outputDir)/publish
retryCountOnTaskFailure: 5
retryCountOnTaskFailure: 5
10 changes: 4 additions & 6 deletions .azure-pipelines/steps/restore-working-directory-for-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ steps:
echo "setting universalArtifactSuffix to ${output}"
echo "##vso[task.setvariable variable=universalArtifactSuffix]${output}"

- task: DownloadPipelineArtifact@2
displayName: Download universal home binaries
inputs:
- template: download-artifact.yml
parameters:
artifact: linux-universal-home-$(universalArtifactSuffix)
path: $(monitoringHome)/${{ parameters.artifactSuffix }}

- task: DownloadPipelineArtifact@2
displayName: Download profiler binaries
inputs:
- template: download-artifact.yml
parameters:
artifact: linux-profiler-home-${{ parameters.artifactSuffix }}
path: $(monitoringHome)
7 changes: 3 additions & 4 deletions .azure-pipelines/steps/restore-working-directory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ parameters:
default: 'build-windows-working-directory'

steps:
- task: DownloadPipelineArtifact@2
displayName: Download working dir
inputs:
- template: download-artifact.yml
parameters:
artifact: ${{ parameters.artifact }}
patterns: "**/@(bin|obj|packages)/**"
path: $(System.DefaultWorkingDirectory)
retryCountOnTaskFailure: 5
retryCountOnTaskFailure: 5
Loading
Loading