Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save larstobi/fe2b94164c1939a3eb9115740d3dd447 to your computer and use it in GitHub Desktop.
Save larstobi/fe2b94164c1939a3eb9115740d3dd447 to your computer and use it in GitHub Desktop.
trigger: none
pool:
vmImage: 'ubuntu-latest'
steps:
- script: |
set -e
# Variables
FEED_NAME="MyFeed"
PACKAGE_NAME="MyUniversalPackage"
PACKAGE_VERSION="1.0.0"
ORGANIZATION_URL="$(System.TeamFoundationCollectionUri)"
PROJECT_NAME="$(System.TeamProject)"
echo "Checking if package '$PACKAGE_NAME' (version $PACKAGE_VERSION) exists in feed '$FEED_NAME'..."
# List all universal packages in the feed and filter by package name and version.
# The command below retrieves all packages and their versions in the feed.
packages_json=$(az artifacts universal list \
--feed "$FEED_NAME" \
--organization "$ORGANIZATION_URL" \
--project "$PROJECT_NAME" \
-o json)
# Using 'jq' to check if the desired package and version exist.
# If you do not have jq installed on the agent, you can parse using grep or another method.
if echo "$packages_json" | jq -e --arg name "$PACKAGE_NAME" --arg version "$PACKAGE_VERSION" \
'.[] | select(.name == $name) | .versions[] | select(. == $version)' > /dev/null; then
echo "Package found!"
echo "##vso[task.setvariable variable=PackageExists]true"
else
echo "Package not found."
echo "##vso[task.setvariable variable=PackageExists]false"
fi
displayName: "Check if Universal Package exists"
- task: UniversalPackages@0
displayName: "Download Universal Package"
condition: eq(variables['PackageExists'], 'true')
inputs:
command: download
feed: "MyFeed"
packageName: "MyUniversalPackage"
packageVersion: "1.0.0"
downloadDirectory: "$(Build.SourcesDirectory)/downloaded_package"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment