Skip to content

Commit 2348e21

Browse files
Copilotscbedd
andauthored
Fix scoped builds crashing on integration publishing (#42014)
When a build is scoped via BuildTargetingString, only targeted packages have artifact directories. The Integration stage was calling Get-ChildItem on all artifact directories, causing a fatal error for non-targeted packages. Add Test-Path check to gracefully skip packages whose artifact directories don't exist, logging a clear message indicating the package was not targeted. Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-python/sessions/034428c7-04c1-4353-9aac-7b0e713c1aaf Co-authored-by: scbedd <45376673+scbedd@users.noreply.github.com>
1 parent 24f2e03 commit 2348e21

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

eng/pipelines/templates/stages/archetype-python-release.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,16 +387,25 @@ stages:
387387
- ${{if ne(artifact.skipPublishDevFeed, 'true')}}:
388388

389389
- pwsh: |
390-
$fileCount = (Get-ChildItem $(Pipeline.Workspace)/${{parameters.ArtifactName}}/${{artifact.name}} | ? {$_.Name -match "-[0-9]*.[0-9]*.[0-9]*a[0-9]*" } | Measure-Object).Count
390+
$artifactDir = "$(Pipeline.Workspace)/${{parameters.ArtifactName}}/${{artifact.name}}"
391+
392+
# When a build is scoped via BuildTargetingString, only targeted packages have
393+
# artifact directories. Skip gracefully if this package was not part of the build.
394+
if (-not (Test-Path $artifactDir)) {
395+
Write-Host "Artifact directory for ${{artifact.name}} not found at '$artifactDir'. Package was not targeted by the current build scope, skipping publish."
396+
exit 0
397+
}
398+
399+
$fileCount = (Get-ChildItem $artifactDir | ? {$_.Name -match "-[0-9]*.[0-9]*.[0-9]*a[0-9]*" } | Measure-Object).Count
391400
392401
if ($fileCount -eq 0) {
393402
Write-Host "No alpha packages for ${{artifact.name}} to publish."
394403
exit 0
395404
}
396405
397-
twine upload --repository $(DevFeedName) --config-file $(PYPIRC_PATH) $(Pipeline.Workspace)/${{parameters.ArtifactName}}/${{artifact.name}}/*-*a*.whl
406+
twine upload --repository $(DevFeedName) --config-file $(PYPIRC_PATH) $artifactDir/*-*a*.whl
398407
echo "Uploaded whl to devops feed $(DevFeedName)"
399-
twine upload --repository $(DevFeedName) --config-file $(PYPIRC_PATH) $(Pipeline.Workspace)/${{parameters.ArtifactName}}/${{artifact.name}}/*-*a*.tar.gz
408+
twine upload --repository $(DevFeedName) --config-file $(PYPIRC_PATH) $artifactDir/*-*a*.tar.gz
400409
echo "Uploaded sdist to devops feed $(DevFeedName)"
401410
displayName: 'Publish ${{artifact.name}} alpha package'
402411

0 commit comments

Comments
 (0)