Last updated Dec 20, 2024

Send Events from Bamboo

If you want to configure your Bamboo pipeline to send an event to a Compass component for a build event, follow these steps.

Send an event when a build is kicked off

  1. Add a Script Task to your Bamboo Plan: In your Bamboo Plan configuration, navigate to the “Tasks” tab for the relevant Job. Click “Add Task” and select “Script” as the type.
  2. Set the description for the task.
  3. Set the Script body to send a CURL request to send an event to Compass, as follows:
1
2
    #!/bin/bash
    set -e
    
    CLOUD_ID="your-cloud-id"
    COMPONENT_ID="your-component-id"
    COMPASS_USER_EMAIL="your-email"
    COMPASS_USER_API_KEY="your-api-key"
    
    NAME=${bamboo.buildPlanName}
    START=${bamboo.buildTimeStamp}
    SEQ=${bamboo.buildNumber}
    DESCRIPTION=${bamboo.planName}
    URL=${bamboo.buildResultsUrl}
    EXTERNAL_ID=${bamboo.planRepository.branchDisplayName}
    PIPELINE_ID=${bamboo.buildNumber}
    START=$(date +%s)
    
    curl --request POST \
    --url https://hello.atlassian.net/gateway/api/compass/v1/events \
    --user "$COMPASS_USER_EMAIL:$COMPASS_USER_API_KEY" \
    --header "Accept: application/json" \
    --header "Content-Type: application/json" \
    --data "{
    \"cloudId\": \"$CLOUD_ID\",
    \"event\": {
        \"displayName\": \"$NAME\",
        \"lastUpdated\": \"$START\",
        \"updateSequenceNumber\": $SEQ,
        \"description\": \"$DESCRIPTION\",
        \"url\": \"$URL\",
        \"externalEventSourceId\": \"$EXTERNAL_ID\",
        \"buildProperties\": {
          \"state\": \"IN_PROGRESS\",
          \"pipeline\": {
            \"pipelineId\": \"$PIPELINE_ID\",
         },
          \"startedAt\": $START
        }
    },
      \"componentId\": \"$COMPONENT_ID\"
    }"

Fill in the values for your Compass site’s cloud ID, the ID of the component you intend to send the event to, your email, and API key.

The CURL request being used is explained in our REST API documentation.

The variables being used here are provided to us by Bamboo, see here. There are various other predefined variables that could be substituted as per your preferences.

Update the event with a result when the build concludes

  1. Add a Final Script Task at the end of your build process within the same job or in a subsequent job that is designated to run last in your plan.
  2. The exit codes of the previous tasks can be used to determine whether the build succeeded or failed, as follows:
1
2
    #!/bin/bash
    set -e 
    
    CLOUD_ID="your-cloud-id"
    COMPONENT_ID="your-component-id"
    COMPASS_USER_EMAIL="your-email"
    COMPASS_USER_API_KEY="your-api-key"
    NAME=${bamboo.buildPlanName}
    START=${bamboo.buildTimeStamp}
    SEQ=${bamboo.buildNumber}
    DESCRIPTION=${bamboo.planName}
    URL=${bamboo.buildResultsUrl}
    EXTERNAL_ID=${bamboo.planRepository.branchDisplayName}
    PIPELINE_ID=${bamboo.buildNumber}
    LAST_UPDATED=$(date +%s)
    STATUS="SUCCESSFUL" # default to success
    
    # Example logic to determine build status based on previous tasks
    # This assumes you have control over the tasks and their exit codes
    if [ $? -ne 0 ]; then
        STATUS="FAILED"
    fi
    
    curl --request POST \
    --url https://hello.atlassian.net/gateway/api/compass/v1/events \
    --user "$COMPASS_USER_EMAIL:$COMPASS_USER_API_KEY" \
    --header "Accept: application/json" \
    --header "Content-Type: application/json" \
    --data "{
      \"cloudId\": \"$CLOUD_ID\",
      \"event\": {
          \"displayName\": \"$NAME\",
          \"lastUpdated\": \"$LAST_UPDATED\",
          \"updateSequenceNumber\": $SEQ,
          \"description\": \"$DESCRIPTION\",
          \"url\": \"$URL\",
          \"externalEventSourceId\": \"$EXTERNAL_ID\",
          \"buildProperties\": {
            \"state\": \"$STATUS\",
            \"pipeline\": {
              \"pipelineId\": \"$PIPELINE_ID\",
            },
            \"startedAt\": $START
          }
      },
      \"componentId\": \"$COMPONENT_ID\"
    }"

Now, your Bamboo pipeline should be configured to send build events to a Compass component of your choosing, and update the event with the correct status once the build concludes.

Rate this page: