Integration: Bamboo Server

Integrate Ghost Inspector with Atlassian Bamboo Server

Search our documentation:

Toggle Documentation Menu

Integration: Bamboo Server

Ghost Inspector test suites can be executed inside your Bamboo Server builds by leveraging the Ghost Inspector API. This tutorial will show you how you can run Ghost Inspector tests against an application running locally on your Bamboo Server base agent.

Note: This example assumes your build agent is running in a Linux-like environment.

Getting started

To get started, we are going to need the following:

Setting up the build

To execute a Ghost Inspector test suite within our project, we're going to add a new Command Line Build Step. Go to your project's build and select Edit Configuration Settings > Build Steps > Add Build Step. From the dropdown menu, select Command Line. From the Run: dropdown select "Custom Script".

To execute your Ghost Inspector test suite with our Project, we're going to need to add a new Task to our Plan Configuration. Go to the Plan you wish to modify, select Actions > Configure Plan > Stages and then select the stage you wish to modify (if you are just setting up Bamboo Server for the first time, this will probably be called Default Stage).

Now click on the stage and navigate to the Tasks panel. Here is where we can add an additional step to our build. Click Add Task and when the new dialog window appears, scroll down and select Script. We should now be here:

Add Ghost Inspector step in Bamboo Server

Add a Task Description of "Run Ghost Inspector Test Suite" and then add the script below to the Script body field.

Custom Script

The following script will handle the actual work of executing the test suite in Ghost Inspector. It will launch your application locally, set up an ngrok tunnel to that application, execute our test suite, and then poll the Ghost Inspector API for the suite results.

Note that you will need to modify the values for API_KEY, APP_PORT, GI_SUITE, and NGROK_TOKEN at the top of the script.

################################
##### CUSTOMIZE BELOW HERE #####

API_KEY='<your-api-key>'
APP_PORT='<your-application-port>'
GI_SUITE='<your-suite-id>'
NGROK_TOKEN='<your-ngrok-auth-token>'

# Tailor this command to suit your application, *must* have the trailing '&'
node server.js &

##### CUSTOMIZE ABOVE HERE #####
################################

# Save the application process ID so we can clean up later
APP_PID=$!
echo "Local application started with PID: $APP_PID"

# unzip may not be available on docker image atlassian/bamboo-base-agent
which unzip
if [ $? -ne 0 ]; then
  wget -qO- https://oss.oracle.com/el4/unzip/unzip.tar | tar -x -C /bin/
fi

# Download ngrok and unzip
wget -qN https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
unzip ngrok-stable-linux-amd64.zip
chmod +x ngrok

# Download JSON parser for determining ngrok tunnel
wget -qN -Ojq https://stedolan.github.io/jq/download/linux64/jq
chmod +x jq

# Intialize ngrok and open tunnel to our application
./ngrok authtoken $NGROK_TOKEN
./ngrok http $APP_PORT > /dev/null &
NGROK_PID=$!

# give ngrok a second to register URLs
sleep 5

# Grab the ngrok url to send to the API
START_URL=$(curl -s 'http://localhost:4040/api/tunnels' | ./jq -r '.tunnels[1].public_url')
echo "Using start URL: $START_URL"

# Set up a couple variables to monitor result state
STATUS='null'
SUITE_RESULT=
PASSING=

# Execute Ghost Inspector suite via API and grab the result ID
EXECUTE_URL="https://api.ghostinspector.com/v1/suites/$GI_SUITE/execute/?apiKey=$API_KEY&startUrl=$START_URL&immediate=1"
echo "Executing suite: $EXECUTE_URL"
RESULT_ID=$(curl -s $EXECUTE_URL | ./jq -r '.data._id')

# for the suite result, sleep for a few seconds if it hasn't changed
echo "Polling for suite results (ID: $RESULT_ID)"
while [ "$STATUS" = 'null' ]; do
  sleep 5
  SUITE_RESULT=$(curl -s "https://api.ghostinspector.com/v1/suite-results/$RESULT_ID/?apiKey=$API_KEY")
  STATUS=$(echo $SUITE_RESULT | ./jq -r '.data.passing')
  echo " - status: $STATUS"
done

# status has been updated, check results for "passing"
if [ "$(echo $SUITE_RESULT | ./jq -r '.data.passing')" != 'true' ]; then
  echo "Suite failed! ¯\_(ツ)_/¯"
  PASSING=1
else 
  echo "Suite passed! \o/"
  PASSING=0
fi

# clean up our processes
kill -9 $APP_PID
kill -9 $NGROK_PID

# return our passing status
exit $PASSING

Wrapping up

From here, execute your first build by clicking Run > Run plan and wait for your build status to update or check out your build log to follow status updates.