Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This article describes the process for configuring automated uploads of mobile app builds to Data Theorem, from a CI/CD pipeline in Screwdriver. At the high-level the process is the following:

...

Please visit https://www.securetheorem.com/sdlc/api_access and copy the key labeled as “Upload API Key”.

Step 2: Save the Upload API Key as a Secret in Screwdriver

...

Enter DT_UPLOAD_API_KEY into the field with the value set to the Upload API Key that was retrieved in Step 1.

Image RemovedImage Added

Step 3: Create a new Screwdriver job for uploading a build to Data Theorem

...

Note: For this example we'll assume it's located in .in $SD_SOURCE_DIR/build/apps/binary.apk.

Second, is the value that should go in the requires section, which is the name of the job that is in charge of building the binary.

...

Info

The environment variable $SD_SOURCE_DIR is a convenient variable that is given to us by Screwdriver that points to the location of the checked-out code.

Please see the documentation for details and other environment variable


Step 4: Create a bash script for uploading a build to Data Theorem

...

Code Block
languagebash
firstline1
titleupload_mobile_binaries_to_datatheorem.sh
linenumberstrue
#!/usr/bin/env bash
# Purpose of this script is to send mobile binary builds to Data Theoerm's Upload API
# Example call:
# ./upload_mobile_binaries_to_datatheorem.sh path/to/mobile/binary/to/upload

# Fail if any commands fails
set -eex

maxRetries=3
for (( retry = 0; retry < maxRetries; retry++ ))
do
  # Step 1: get the upload URL
  echo "Get upload url"
  step1_response=$(curl -s -w "%{http_code}" -X POST -H "Authorization: APIKey ${DT_UPLOAD_API_KEY}"  --data ""  https://api.securetheorem.com/uploadapi/v1/upload_init)
upload_url=$(echo   http_code=${step1_response: -3}
  response_body=${step1_response::-3}

  # For older versions of bash e.g. GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin21)
  # response_body=${step1_response%???}
  # http_code=${step1_response#${response_body} | cut -f 3 -d" " | tr -d '"')

}

  # Check that http status code is 200
  [ ! ${http_code} -eq 200 ] && echo ${response_body} && exit 1
  upload_url=$(echo ${response_body} | jq -r ".upload_url")
  echo ${upload_url}

  # Step 2: upload the mobile binary APK
  echo "Upload app"
  step2_response=$(curl -F file=@${1} ${upload_url}) && --retry 3)

echo "Response from Data Theorem"
echo ${step2_response}

echo ${step2_response} && break
done

if [ ${retry} -ge ${maxRetries} ]; then
  echo "Upload failed after ${maxRetries} attempts"
  exit 1
fi


The script will fail if any of the commands are unsuccessful. 

...

Code Block
linenumberstrue
# ....
# Top level
cache:
  event: [path/to/built/binary$SD_SOURCE_DIR/build/apps/]  # Things to be cached/shared between jobs

# ....
jobs:
  main:
    # ...  
# ....

...