Fix duplicate artifact error on PR pipeline job re-runs - #4508
Conversation
Pipeline artifact names must be unique within a build, so re-running a failed job in the sqlclient-pr pipeline failed with "Artifact build_and_pack_projects already exists for build <id>." Suffix the published artifact names with $(System.JobAttempt) in the pack, coverage, and test-results publish steps. System.JobId is stable across attempts of the same job, so the test-results artifact had the same latent collision. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8612610a-cd1b-4668-b818-ce555b5ffd14
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates Azure Pipelines artifact naming to avoid collisions when re-running failed jobs by including the job attempt number in published artifact names.
Changes:
- Append
$(System.JobAttempt)to pipeline artifact names for test results, build output, and merged coverage. - Add inline documentation explaining why attempt-based uniqueness is required.
- Add a display name to the build output publish step.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| eng/pipelines/pr/steps/publish-test-results-step.yml | Makes test-results artifact names unique per job attempt and documents the rationale. |
| eng/pipelines/pr/stages/pack-stage.yml | Makes build output artifact names unique per job attempt and improves step labeling/docs. |
| eng/pipelines/pr/stages/collect-coverage-stage.yml | Makes merged coverage artifact names unique per job attempt and documents the rationale. |
Address review feedback by moving the artifact base names into pr-variables.yml and passing them into the pack and coverage stage templates, matching the existing testResultsArtifactBaseName pattern. This keeps producers and any future consumers in sync via a single definition. Also correct a doc comment to reference parameters.testResultsArtifactBaseName. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8612610a-cd1b-4668-b818-ce555b5ffd14
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4508 +/- ##
==========================================
- Coverage 64.71% 63.92% -0.79%
==========================================
Files 288 283 -5
Lines 44088 67041 +22953
==========================================
+ Hits 28532 42858 +14326
- Misses 15556 24183 +8627
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Suppressed comments (1)
eng/pipelines/pr/variables/pr-variables.yml:56
- The comment for
testResultsArtifactBaseNamesays onlySystem.JobIdshould be appended to prevent collisions, but the PR pipeline now also appendsSystem.JobAttemptbecauseSystem.JobIdis stable across job re-runs. Updating this comment avoids future confusion about the required artifact naming scheme.
# Base name of the merged code coverage artifact published by the coverage stage.
- name: coverageArtifactBaseName
value: "merged_coverage"
# Base name of the test result artifacts. Job ID should be appended to this to prevent collision.
Description
Re-running a failed job in the
sqlclient-prpipeline fails with:Azure Pipelines requires artifact names to be unique within a build. The pack job publishes its build output under a fixed name, so attempt 2 of that job tries to publish an artifact that attempt 1 already created and the re-run fails before it can do anything useful.
This change suffixes the published artifact names with
$(System.JobAttempt)in the PR pipeline:eng/pipelines/pr/stages/pack-stage.yml-build_and_pack_projects_attempt$(System.JobAttempt). This is the reported failure. Also added adisplayNameto the publish step so it is easier to spot in the log.eng/pipelines/pr/steps/publish-test-results-step.yml- appended the attempt number.System.JobIdis stable across attempts of the same job, so the test-results artifact carried the same latent collision and would fail on any test job re-run.eng/pipelines/pr/stages/collect-coverage-stage.yml-merged_coverage_attempt$(System.JobAttempt), for the same reason.Notes for reviewers:
build_and_pack_projectsby name; it is published for diagnostics only, so the rename has no consumers to update.itemPattern: '**/*.coverage'with no artifact-name filter, so it keeps working with the new names.Issues
N/A - reported directly from a pipeline failure on build 165347.
Testing
No automated tests. These are Azure Pipelines YAML changes with no product code impact; the repo has no YAML pipeline test harness. Validated that all three files still parse as YAML and confirmed by inspection that no template or task references the renamed artifacts. Final verification is the pipeline itself: the pack, test, and coverage jobs should publish normally, and re-running a failed job should now succeed instead of erroring on a duplicate artifact name.
Guidelines
Please review the contribution guidelines before submitting a pull request: