Integration: Bitbucket Pipelines

Integrate Ghost Inspector with Bitbucket Pipelines

Search our documentation:

Toggle Documentation Menu

Integration: Bitbucket Pipelines

Ghost Inspector test suites can be executed within your Bitbucket Pipelines build by utilizing the Ghost Inspector base Docker image ghostinspector/test-runner-node available on Docker Hub. This document will take you through the process of setting up and testing a simple Node.js application in Bitbucket Pipelines.

Note: While we are going to be using Node.js for the purposes of this document, the examples should be easily adaptable to other runtimes by customizing our test runner Dockerfile.

Getting started

In order to get started, you are going to need the following:

Our application

First off we'll set up our new repo for our application, we'll call it my-app. In the Include a README? field we will select Yes, with a template so Bitbucket will initialize the repo for us:

Set up a new repo in Bitbucket

Now that we have a fresh git repository, we can click on Source > New file and add some code for our index.js file:

Adding our index.js file in Bitbucket

Here's the code:

  var http = require('http'); 

  http.createServer(function (req, res) { 
    res.writeHead(200, {'Content-Type': 'text/html'}); 
    <head><title>My simple node app</title></head>
      <h2>Hello Ghost Inspector!</h2>
      <p>This is just a simple Node.js app.</p>
  console.log('Server running on port 8000.');

This basic app is going to accept any incoming request on port 8000 and send a simple HTML response message which we are going to test against in a bit.


Next we are going to add a pipeline configuration. Go to Pipelines and scroll down to select the Javascript template. We will modify the configuration to extend the ghostinspector/test-runner-node Docker image:

Adding our bitbucket-pipelines.yml config file in Bitbucket

Here's the bitbucket-pipelines.yml code, drop it into the editor and commit the new file:

image: ghostinspector/test-runner-node

    - step:
          - /bin/runghostinspectorsuite index.js

As soon as we save that file Bitbucket will take us to the Pipelines page where we will see our Pipeline #1 has failed:

Our first Bitbucket Pipelines build fails

This is because we haven't added the necessary configuration for our test runner image yet. We can do this through the use of Environment Variables.

Pipeline environment configuration

Now let's navigate to Settings > Pipelines > Environment Variables. At a minumum we are going to need to add the following:

You also have the ability to pass in custom variables to your Ghost Inspector tests by prefixing the parameter with GI_PARAM_, for instance:

My test suite

I haven't set up a test suite for this app yet, so I'm going to do that now. I'll create a new Suite called Test my-app and add a single test with a couple assertions:

Setting up my Ghost Inspector test steps

This will check that the h2 element contains Hello Ghost Inspector! and my p element contains simple Node.js app.

Now that I have my suite ID I'll drop that in my Pipelines environment variables configuration and save it:

Adding environment variables

Running the build

From here we should be able to run the build again and watch the progress of the pipeline. We will need to add a new commit to the repository in order to trigger the pipeline. While the build is running, our test script will fire up your application and then get ngrok to set up a temporary tunnel to our Docker container. Once that's set up, ngrok will provide us with a start URL to use for our test. If you're quick (or your tests take a while), you can grab the URL and have a quick peek at your app running inside the pipeline:

Our application running inside Bucketbucket Pipelines

After a minute, we should see our pipeline pass:

Our pipeline succeeded

And we can check our test suite to verify:

Our Ghost Inspector test passed

Wrapping up

And that's it! If you've made it this far you should have a passing Bitbucket Pipeline, fully tested by your Ghost Inspector test suite.

If you should have any trouble with this tutorial or any other issues, feel free to reach out to our support team and we'll be happy to help you along.