Skip to content

Integration with Bitbucket Pipelines

AirQuick edited this page Oct 28, 2020 · 10 revisions

Bitbucket Pipelines is a built in CI system for Atlassian Bitbucket.

The following example illustrates how to run XSpec tests in a Pipelines build for a project hosted on Bitbucket.

  1. Create the following bitbucket-pipelines.yml in the root of your repository:

    pipelines:
      default:
        - step:
            script:
              # Install XSpec
              - echo "Installing XSpec"
              - git clone -b master https://github.com/xspec/xspec.git /tmp/xspec
              # Install Saxon
              - echo "Installing Saxon"
              - mkdir -p /tmp/saxon
              - export SAXON_CP=/tmp/saxon/saxon9he.jar
              - wget -O "${SAXON_CP}" https://repo1.maven.org/maven2/net/sf/saxon/Saxon-HE/9.9.1-7/Saxon-HE-9.9.1-7.jar
              # script
              - cd test
              - echo "execute XSpec unit tests"
              - ./run-xspec-tests.sh

    The commands install XSpec in /tmp/xspec and the Saxon processor in /tmp/xspec/saxon and set the path to the Saxon jar. The commands labelled script navigate into the test directory and run a shell script that executes all the XSpec test suite. Modify the test directory to the location where your XSpec tests are stored.

  2. Create the shell script run-xspec-tests.sh that runs all the XSpec tests in the test directory:

    #! /bin/bash
    
    for xspecfile in *.xspec; do
        if /tmp/xspec/bin/xspec.sh -e "${xspecfile}" &> result.log; then
            echo "OK: ${xspecfile}"
        else
            echo "FAILED: ${xspecfile}"
            echo "---------- result.log"
            cat result.log
            echo "----------"
            exit 1
        fi
    done

    This shell script outputs the name of the successful XSpec test executed. If an XSpec fails, the script stops, provides the name of the failing test and output the error message stored in the log file result.log.

    Note that this run-xspec-tests.sh is only for illustration purposes. It is very slow. For more serious purposes, consider using Ant.

  3. Push to your Bitbucket repository the following files:

    • bitbucket-pipelines.yml: this must be pushed to the root of the repository you want to test. You can configure different branches to use different scripts.
    • run-xspec-tests.sh: ideally this should be pushed to the same directory where your XSpec tests are located.
    • your XSpec tests

Here is an output of a successful build with XSpec tests on Pipelines:

Integration with Bitbucket Pipelines

Clone this wiki locally