Trigger Tests on Testsigma and Deploy on passed tests after code change on Bitbucket

Testsigma offers powerful Web hooks for triggering Testsigma Executions remotely from any third-party tool that provides a Command Line Interface(CLI). In this guide, let us see how we can integrate Testsigma in CircleCI for automatically triggering Test Executions with code change on Bitbucket Repo and wait for the tests to pass and then proceed with deployment.

 

Prerequisite

1. A CircleCI Account

If you are new to CodeShip, please follow the following link to create an Account(using your email or OAuth), Add your Organisation and Create a Project - Signing up for new Codeship Account


2. Connect your Source Code Management(SCM) tool such as Github, BitBucket or GitLab to your account.

In this Guide, we will be using Bitbucket as our SCM.

 

Integrating Bitbucket/GitHub to CircleCI

During the on-boarding, you are asked to log into CircleCI using one of the SCM tool login - Github/Bitbucket.


Once you integrate the account, the repositories in your SCM will be visible in CircleCI. You can set up any of them for Continuous Delivery using the 'Set Up Project' button.


1. Clicking on Set up Project takes us to the Set Up page as shown below:


2. Modify the config.yml file and include a job to run the bash script file that initiates Testsigma Execution and waits for its completion. Here's a sample entry for config.yml file:

# Java Maven CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-java/ for more details
#
version: 1.0
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/openjdk:8-jdk
      - image: debian:stretch
      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/postgres:9.4
    working_directory: ~/repo
    environment:
      # Customize the JVM maximum heap limit
      MAVEN_OPTS: -Xmx3200m
    steps:
      - checkout
      # Download and cache dependencies
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "pom.xml" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-
      - run: mvn dependency:go-offline
      - save_cache:
          paths:
            - ~/.m2
          key: v1-dependencies-{{ checksum "pom.xml" }}
      # run tests!
      - run: chmod a+x ./trigger_testsigma_tests_and_wait.sh
      - run: ./trigger_testsigma_tests_and_wait.sh


3. Now, click on Start Building button on the top right to start a test build. You will be greeted with a dialog stating that the config.yml will be added to the selected Repo by CircleCI.


4. Click on Add Config button to Add the Config and start building. It will take you to the Pipelines page.


That's it. Integration of your Repo to CircleCI tool is complete. Commits to your repository would now trigger a build automatically.

 

Integrating Testsigma with CircleCI


The initial build of your Project will fail since we have not supplied the trigger_testsigma_tests_and_wait.sh file. We need to add that manually to the Repository. You can find the file in the below article:

Generic Shell Script for Integrating with CI/CD Tools


1. Go to Testsigma Test Plans page to get the <Execution ID> and <Test Plan Trigger URL> as shown below:


2. Update your <Username>, <Password> and <Test Plan Trigger URL> in the above script before uploading that to the Repo.


3. Now add the trigger_testsigma_tests_and_wait.sh file to the src folder of your Repository and make the commit.


With the above settings, the build will be triggered whenever there is a change in the repository and as soon as the build is triggered, the tests will begin in Testsigma. The script will wait until the test completes and checks that the result of the tests is passed.



Happy Test Automation!