Creating a Build

Bitbar Build service is currently an API only service. The following steps guide you how to create your first build on the service. You can install Testdroid API client to use functions provided by python API client from command line:

$ pip install testdroid

(Note: in the future this will be part of the Bitbar API client)

Get All Jobs

To get started with build, you need to have a builder dedicated for you to use. Please handle this with Bitbar sales. Also you need to get your API_KEY from your account settings in Bitbar Cloud.

CURL

$ BITBAR_BUILD_TOKEN=<YOUR-TOKEN>
$ curl -H Accept:application/json -u $BITBAR_BUILD_TOKEN: https://<customer cloud URL>/cloud/api/v2/me/jobs | python -m json.tool

TESTDROID API CLIENT

$ testdroid --apikey $BITBAR_BUILD_TOKEN --url https://<customer cloud URL>/cloud/ jobs

Step 1: Create a Job

You’ll need to have an existing Jenkinsfile that defines the details of your build. Here the Jenkinsfile is in the @android-job file that’s uploaded to the build project.

Here’s how the android job file looks like:

name=nameOfBuild&content=try {
  node("macos10.12.6") {
    stage("Preparation") {
      sh("curl -o in.tar '$BB_INPUT_FILE_SET_URL'")
      sh("tar -xzvf in.tar")
    }

    stage("Build") {
      sh('pwd')
      dir('BitbarSampleApp') {
        sh('./gradlew build')
      }
    }

    stage("Result") {
      sh("curl -X PUT '$BB_OUTPUT_FILE_SET_URL' --upload-file BitbarSampleApp/app/build/outputs/apk/app-debug.apk")
    }
  }
}

catch (exc) {
}

finally {
  node() {
    sh("""
    curl -X POST $BB_CLOUD_URL/api/v2/users/$BB_USER_ID/jobs/$BB_JOB_ID/builds/$BB_BUILD_ID?buildNumber=$BUILD_NUMBER \
    -u '$BB_API_KEY:'
    """)
  }
}

In the above name=nameOfBuild&content= is not part of the Jenkinsfile but used here to allow Curl to upload the file to you builder. Create a new build job by uploading the above build to the builder. When using api client there is no need to include this part the content

CURL

$ curl -X POST -H Accept:application/json -u $BITBAR_BUILD_TOKEN: https://<customer cloud URL>/cloud/api/v2/me/jobs --data-binary @android-job | python -m json.tool

TESTDROID API CLIENT

$ testdroid --apikey $BITBAR_BUILD_TOKEN --url https://<customer cloud URL>/cloud/ create-job <name-of-the-job> "`cat Jenkinsfile`"

Make note of the id in the response message as it is needed in next steps.

Let’s define it as $BITBAR_BUILD_JOB_ID for later use.

$ BITBAR_BUILD_JOB_ID=<JOB-ID-GENERATED>

Step 2: Upload File

CURL

$ curl -X POST -H Accept:application/json -u $BITBAR_BUILD_TOKEN: https://<customer cloud URL>/cloud/api/v2/me/files -F "file=@BitbarSampleApp.tar.gz" | python -m json.tool

TESTDROID API CLIENT

$ testdroid --apikey $BITBAR_BUILD_TOKEN --url https://<customer cloud URL>/cloud/ upload-file <file path>

Again keep somewhere the file id from the response and make it into an environment variable to be used by later steps.

$ BITBAR_BUILD_FILE_ID=<FILE-ID-GENERATED>

Step 3: Start Job Based on ID

CURL

$ curl -X POST -H Accept:application/json -u $BITBAR_BUILD_TOKEN: https://<customer cloud URL>/cloud/api/v2/me/jobs/$BITBAR_BUILD_JOB_ID/builds?fileId=$BITBAR_BUILD_FILE_ID | python -m json.tool
$ BITBAR_BUILD_ID=<BUILD-ID-GENERATED>

TESTDROID API CLIENT

$ testdroid --apikey $BITBAR_BUILD_TOKEN --url https://<customer cloud URL>/cloud/ create-build $BITBAR_BUILD_JOB_ID "{\"file\": $BITBAR_BUILD_FILE_ID}"
$ BITBAR_BUILD_ID=<BUILD-ID-GENERATED>

Again the build id is stored as environment variable so, polling for results is easier.

Step 4: Get build status or Wait until build completes

CURL

$ curl -H Accept:application/json -u $BITBAR_BUILD_TOKEN: https://<customer cloud URL>/cloud/api/v2/me/jobs/$BITBAR_BUILD_JOB_ID/builds/$BITBAR_BUILD_ID | python -m json.tool

TESTDROID API CLIENT

$ testdroid --apikey $BITBAR_BUILD_TOKEN --url https://<customer cloud URL>/cloud/ wait-build --interval 1 $BITBAR_BUILD_JOB_ID $BITBAR_BUILD_ID

Step 5: Get Result

CURL

$ curl -H Accept:application/json -u $BITBAR_BUILD_TOKEN: https://<customer cloud URL>/api/v2/me/jobs/$BITBAR_BUILD_JOB_ID/builds/$BITBAR_BUILD_ID/output-file-set/files | python -m json.tool

TESTDROID API CLIENT

$ testdroid --apikey $BITBAR_BUILD_TOKEN --url https://<customer cloud URL>/cloud/  download-builds-files $BITBAR_BUILD_JOB_ID $BITBAR_BUILD_ID