How to download latest successful build artifacts via script

#1

Hi! we are using the service but we need a way to download the generated artifacts via an automated script as we could do with Jenkins, the idea is that one script we have, get the latest successful build artifact apk files, and then run the automated E2E tests for our application.

0 Likes

#2

for now im using the Bitrise API to download the artifacts, but its not an easy thing to do, considering the way the tool simplifies tasks for developers, it will be great to have an easy way to provide this as a step.

BITRISE_TOKEN=<YOUR_TOKEN>
BITRISE_APP_SLUG=<YOUR_APP_SLUG>
BITRISE_APP_BRANCH=develop
BITRISE_API_BUILD_SLUG_URL="https://api.bitrise.io/v0.1/apps/${BITRISE_APP_SLUG}/builds?branch=${BITRISE_APP_BRANCH}&status=1&limit=1"
BITRISE_APP_BUILD_SLUG=
BITRISE_API_BUILD_ARTIFACTS_URL=

# Get app build slug
BITRISE_APP_BUILD_SLUG=$(curl -H "Authorization: ${BITRISE_TOKEN}" "${BITRISE_API_BUILD_SLUG_URL}" | jq '.data | .[] | .slug' | tr -d \")
echo $BITRISE_APP_BUILD_SLUG
# Get app build slug artifacts
BITRISE_API_BUILD_ARTIFACTS_URL="https://api.bitrise.io/v0.1/apps/${BITRISE_APP_SLUG}/builds/${BITRISE_APP_BUILD_SLUG}/artifacts"
BITRISE_API_BUILD_ARTIFACTS_SLUGS=( $(curl -H "Authorization: ${BITRISE_TOKEN}" "${BITRISE_API_BUILD_ARTIFACTS_URL}" | jq '.data | .[] | .slug' | tr -d \") )
#echo $BITRISE_API_BUILD_ARTIFACTS_SLUGS
printf "%s\n" "${BITRISE_API_BUILD_ARTIFACTS_SLUGS[@]}"

# Get app build slug artifacts download urls and download artifacts
for i in "${BITRISE_API_BUILD_ARTIFACTS_SLUGS[@]}"
do
   :
   # do whatever on $i
   echo $i
   BITRISE_API_BUILD_ARTIFACT_URL="https://api.bitrise.io/v0.1/apps/${BITRISE_APP_SLUG}/builds/${BITRISE_APP_BUILD_SLUG}/artifacts/$i"
   echo $BITRISE_API_BUILD_ARTIFACT_URL
   #curl -H "Authorization: ${BITRISE_TOKEN}" "${BITRISE_API_BUILD_ARTIFACT_URL}" | jq
   # TODO Get artifact version from ".data.artifact_meta.app_info.version_name"
   BITRISE_API_BUILD_ARTIFACT_SLUG_VERSION=$(curl -H "Authorization: ${BITRISE_TOKEN}" "${BITRISE_API_BUILD_ARTIFACT_URL}" | jq '.data.artifact_meta.app_info.version_name' | tr -d \")
   echo $BITRISE_API_BUILD_ARTIFACT_SLUG_VERSION
   BITRISE_API_BUILD_ARTIFACT_SLUG_URL=$(curl -H "Authorization: ${BITRISE_TOKEN}" "${BITRISE_API_BUILD_ARTIFACT_URL}" | jq '.data | .expiring_download_url' | tr -d \")
   echo "$BITRISE_API_BUILD_ARTIFACT_SLUG_URL"
   curl -OL "$BITRISE_API_BUILD_ARTIFACT_SLUG_URL"
done
0 Likes

#3

Hi @LeaChescotta
Thank you for reaching out to bitrise.
From the looks of the details, this seems to be a feature request for the product.
I will let the product team about this feature request.

Thanks
Chaitanya

1 Like