Circle CI

Please find below an example configuration file (typically stored in a file named .circleci/config.yml) which builds your project, then uses a curl command to upload the build file to GPT Driver. It also extracts the buildId from the API response and persists it for use in later steps using the special $BASH_ENV file.

version: 2.1

jobs:
  upload-build:
    docker:
      - image: cimg/base:stable
    steps:
      - checkout

      - run:
          name: Install Dependencies
          command: |
            sudo apt-get update
            sudo apt-get install -y jq curl

      - run:
          name: Build Project
          command: |
            echo "Building the project..."
            # Replace this with your actual build commands.
            # For example: ./gradlew assembleDebug

      - run:
          name: Upload Build File with Error Handling
          command: |
            # Replace <build_file_path>, <ORG_KEY>, and <platform> with your actual values.
            response=$(curl -i -X POST \
                        -H "Content-Type: multipart/form-data" \
                        -F "build=@<build_file_path>" \
                        -F "organisation_key=<ORG_KEY>" \
                        -F "platform=<platform>" \
                        -F "metadata={}" \
                        https://api.mobileboost.io/uploadBuild/)
            
            # Check if curl executed successfully.
            if [ $? -ne 0 ]; then
              echo "Error: Failed to execute the curl command."
              exit 1
            fi

            # Extract the last HTTP status code from the response.
            status_code=$(echo "$response" | awk '/HTTP\// {print $2}' | tail -n1)
            if [ "$status_code" != "200" ]; then
              echo "Error: Upload failed with HTTP status code $status_code."
              echo "Response: $response"
              exit 1
            fi

            # Extract the buildId
            json_response=$(echo "$response" | awk '/^{/ {print}')
            buildId=$(echo "$json_response" | jq -r '.buildId')
            if [ -z "$buildId" ] || [ "$buildId" == "null" ]; then
              echo "Error: buildId not found in response. JSON: $json_response"
              exit 1
            fi

            echo "Build ID: $buildId"
            # Persist the buildId to the environment for subsequent steps.
            echo "export BUILD_ID=$buildId" >> $BASH_ENV

workflows:
  version: 2
  build_and_upload:
    jobs:
      - upload-build

Last updated