Skip to content

Instantly share code, notes, and snippets.

@larstobi
Last active October 29, 2024 14:24
Show Gist options
  • Save larstobi/ae9db1486ccc4a2ef3405b9b05ba6bfc to your computer and use it in GitHub Desktop.
Save larstobi/ae9db1486ccc4a2ef3405b9b05ba6bfc to your computer and use it in GitHub Desktop.
- task: Bash@3
displayName: 'Check if Package Exists'
inputs:
targetType: 'inline'
script: |
set -e
# Configure default organization and project
az devops configure --defaults organization=$(System.TeamFoundationCollectionUri) project=$(System.TeamProject)
# Authenticate with Azure DevOps
az devops login --token $(System.AccessToken)
# Attempt to download the package
az artifacts universal download \
--feed "$(feedName)" \
--name "$(packageName)" \
--version "$(packageVersion)" \
--path "$(Build.ArtifactStagingDirectory)/temp_download"
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo "Package exists."
echo "##vso[task.setvariable variable=PackageExists]true"
else
echo "Package does not exist or an error occurred."
echo "##vso[task.setvariable variable=PackageExists]false"
fi
# Clean up temporary files
rm -rf "$(Build.ArtifactStagingDirectory)/temp_download"
set -e # Re-enable exit on error
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- task: UniversalPackages@0
displayName: 'Publish Universal Package'
inputs:
command: 'publish'
publishDirectory: '$(Build.ArtifactStagingDirectory)'
feedsToUsePublish: 'internal'
vstsFeedPublish: 'YourFeedID'
vstsFeedPackagePublish: '$(packageName)'
packagePublishVersion: '$(packageVersion)'
condition: ne(variables['PackageExists'], 'true')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment