Hey everyone, I just wanted to quickly share a new article we have on sending build and deployment activity from Bamboo to Compass. The example script in the article will help you send build events, which are just one of the many event types we support and that you can see on the Compass activity feed. If you're using Bamboo check this out and let us know if it helped!
@Josh Campbell why do you need 2 scripts? would you not just run this as a 'final tasks' in bamboo? or am I missing something?
Also I have something very similar but I'm using the compass.yml file that would be added to the code repo
#!/usr/bin/env bashset -e## debug outputDEBUG=true## this script is used for bamboo build events## https://developer.atlassian.com/cloud/compass/rest/api-group-events/#api-compass-v1-events-post# https://developer.atlassian.com/cloud/compass/rest/intro/#version## check to see if jq is installedif ! command -v jq &> /dev/nullthen echo "jq could not be found, please install jq" exit 1fi## check to see if yq is installedif ! command -v yq &> /dev/nullthen echo "yq could not be found, please install yq" exit 1fiCOMPASS_CONFIG_FILE=compass.ymlCOMPASS_CONFIG_FILE_EXISTS=true## check if compass.yml existsif [ ! -f "$COMPASS_CONFIG_FILE" ]then echo "File $COMPASS_CONFIG_FILE does not exist, please add the compass.yml file from your component https://acme.atlassian.net/compass/components to your repo in the project root" COMPASS_CONFIG_FILE_EXISTS=falsefiif [ "$COMPASS_CONFIG_FILE_EXISTS" = true ]then ## get the compass id from the compass.yml file COMPASS_COMPONENT_ID=$(yq e '.id' <(cat "$COMPASS_CONFIG_FILE")) ## compass settings :: this would be your instance name. not acme COMPASS_CLOUD_INSTANCE=acme COMPASS_REST_API_VERSION=v1 ## create api token for your user https://id.atlassian.com/manage-profile/security ## aded to bamboo as global variables, you can name them whatever COMPASS_USER_EMAIL=${bamboo.compass.rest.api.user.email} COMPASS_USER_TOKEN=${bamboo.compass.rest.api.token} ## base atlassian url ATLASSIAN_BASE_URL="https://$COMPASS_CLOUD_INSTANCE.atlassian.net" ATLASSIAN_CLOUD_ID_URL="$ATLASSIAN_BASE_URL/_edge/tenant_info" ## get atlassian cloud id ATLASSIAN_CLOUD_ID=`curl --request GET \ --url $ATLASSIAN_CLOUD_ID_URL \ --user $COMPASS_USER_EMAIL:$COMPASS_USER_TOKEN \ --header 'Accept: application/json' \ | jq --raw-output '.cloudId'` ## compass event api COMPASS_BASE_URL="$ATLASSIAN_BASE_URL/gateway/api/compass/$COMPASS_REST_API_VERSION/events" BAMBOO_BUILD_STATE=UNKNOWN BUILD_STATUS=${bamboo_jobFailed} ## note there are other values that can be set for compass ## IN_PROGRESS, SUCCESSFUL, CANCELLED, FAILED, ERROR, TIMED_OUT, UNKNOWN if [[ "$BUILD_STATUS" == "true" ]] then BAMBOO_BUILD_STATE=FAILED else BAMBOO_BUILD_STATE=SUCCESSFUL fi COMPASS_BUILD_TIMESTAMP_FINISHED=$(date -u +'%Y-%m-%dT%H:%M:%SZ') COMPASS_BUILD_DISPLAY_NAME="BUILD: ${bamboo.buildPlanName}" COMPASS_BUILD_UPDATE_SEQUENCE_NUMBER="${bamboo.buildNumber}" COMPASS_BUILD_DESCRIPTION="${bamboo.planName}" COMPASS_BUILD_URL="${bamboo.buildResultsUrl}" COMPASS_BUILD_EXTERNAL_EVENT_SOURCE_ID="${bamboo.planRepository.branchDisplayName}" COMPASS_BUILD_STARTED_AT="${bamboo.buildTimeStamp}" COMPASS_BUILD_PIPELINE_ID="${bamboo.buildNumber}" ## data needs to be JSON, use JQ for this COMPASS_EVENT_JSON_DATA=$( jq -n \ --arg cloudId "$ATLASSIAN_CLOUD_ID" \ --arg cDisplayName "$COMPASS_BUILD_DISPLAY_NAME" \ --arg cLastUpdated "$COMPASS_BUILD_TIMESTAMP_FINISHED" \ --arg cUpdateSequenceNumber $COMPASS_BUILD_UPDATE_SEQUENCE_NUMBER \ --arg cDescription "$COMPASS_BUILD_DESCRIPTION" \ --arg cUrl "$COMPASS_BUILD_URL" \ --arg cExternalEventSourceId "$COMPASS_BUILD_EXTERNAL_EVENT_SOURCE_ID" \ --arg cState "$BAMBOO_BUILD_STATE" \ --arg cStartedAt "$COMPASS_BUILD_STARTED_AT" \ --arg cPipelinePipelineId "$COMPASS_BUILD_PIPELINE_ID" \ --arg componentId "$COMPASS_COMPONENT_ID" \ '{ cloudId: $cloudId, event: {build: {displayName: $cDisplayName, lastUpdated: $cLastUpdated, updateSequenceNumber: $cUpdateSequenceNumber, description: $cDescription, url: $cUrl, externalEventSourceId: $cExternalEventSourceId, buildProperties: {state: $cState, startedAt: $cStartedAt, pipeline: {pipelineId: $cPipelinePipelineId}}}}, componentId: $componentId}' ) COMPASS_EVENT=`curl --request POST \ --url $COMPASS_BASE_URL \ --user $COMPASS_USER_EMAIL:$COMPASS_USER_TOKEN \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --data "$COMPASS_EVENT_JSON_DATA"` echo "COMPASS_EVENT: $COMPASS_EVENT" if [ "$DEBUG" = true ] then echo "COMPASS_COMPONENT_ID: $COMPASS_COMPONENT_ID" echo "COMPASS_BASE_URL: $COMPASS_BASE_URL" echo "ATLASSIAN_CLOUD_ID: $ATLASSIAN_CLOUD_ID" echo "BUILD_STATUS: $BUILD_STATUS" echo $COMPASS_EVENT_JSON_DATAfielse echo "skipping compass event build, compass.yml does not exist"fi
It looks like you're new here. Sign in or register to get started.