Reflect Docs

Connecting to CI/CD

Automatically execute Reflect tests from within your Continuous Integration/Continuous Deployment pipeline.

Via the Reflect API, you can automatically execute tests associated with a given tag (e.g. a ‘smoke-test’ tag). Below we’ve outlined how to trigger a Reflect API request from within several popular CI/CD tools.

Azure Pipelines

Jobs in Azure DevOps can be defined either as agentless / Server jobs or as a Pipeline job that is invoked on a remote agent. See below for examples using both flavors of job definition:

Agentless

steps:
- task: InvokeRESTAPI@1
  displayName: 'Invoke REST API: POST'
  inputs:
    serviceConnection: 'Reflect Service Connection'
    headers: |
     {
      "x-api-key": "<your api key goes here>"
     }
    body: |
     {}
  enabled: true

Pipeline job

steps:
- task: CdiscountAlm.rest-call-build-task.custom-build-task.restCallBuildTask@0
  displayName: 'Rest call POST'
  inputs:
    webserviceEndpoint: 'Reflect Service Connection'
    httpVerb: POST
    headers: |
     {
      "x-api-key": "<your api key goes here>"
     }
    body: |
     {}
  enabled: true

For more information on Azure Pipelines jobs, please refer to Microsoft’s online documentation

Bitbucket Pipeline

To kick off Reflect tests as part of your pipeline, you’ll need to add an additional step in your existing bitbucket-pipelines.yml

pipelines:
  branches:
    master:
    ...
    - step:
      name: Regression Tests
      script:
      - curl -X POST --data "{}" -H "x-api-key: <API-KEY>" https://api.reflect.run/v1/tags/<TAG-SLUG>/executions

We recommend that you set up your Reflect API Key as a secure environment variable rather than including it directly in your bitbucket-pipelines.yml file.

For more information on setting up Bitbucket Pipeline, please consult Bitbucket’s online documentation.

CircleCI

To enable automated test execution, add an additional step in your CircleCI config.yml:

jobs:
  build:
    steps:
    ...
    - run:
      name: Regression Tests
      command: |
        curl -X POST --data "{}" -H "x-api-key: <API-KEY>" https://api.reflect.run/v1/tags/<TAG-SLUG>/executions

Your Reflect API key should be set outside of version control as an Environment Variable rather than hard-coded in your config.yml.

More information on calling REST APIs as part of a CircleCI build is available on the CircleCI blog.

GitHub Actions

Integrating with Github Actions

GitHub Actions allow you to execute commands after some event occurs in your repository. One example is to execute Reflect tests after deploying your application to a new environment. Triggering the tests is as simple as issuing an HTTP request to the Reflect API.

on:
  push:
    branches:
      - "master"

jobs:
  run-staging-tests:
    runs-on: ubuntu-latest
    steps:
      - name: Run Reflect regression test
      - run: curl \
          -X POST \
          -H "X-API-KEY: <API-KEY>" \
          -d "{}" \
          https://api.reflect.run/v1/tags/<TAG-SLUG>/executions
Integrating via Webhooks

Alternatively you can trigger Reflect tests by configuring a Webhook. For example, you can set up your Webhook to execute when a deployment status event with the value success is returned, meaning that a deployment of a git commit hash to a given environment has completed successfully.

For more information on configurating Webhooks, consult Github’s online documentation.

Heroku

To configure Reflect tests to execute after a Heroku deployment, add the following Procfile with the command release: chmod u+x release.sh && ./release.sh

#!/bin/sh
#
# Execute commands after Heroku environment is fully deployed.
#
if [[ -z "${DEPLOY_ENV}" ]]; then
    echo "Environment variable not set"
else
    if [ "${DEPLOY_ENV}" = "staging" ]; then
        Tag="<my-tag>"
        echo "=== Triggering Reflect tests ==="
        echo "Tag=${Tag}"
        echo "Response:"
        curl --silent -X POST \
        -H "X-API-KEY: ${REFLECT_API_KEY}" \
        https://api.reflect.run/v1/tags/${Tag}/executions
    fi
fi

Gitlab CI/CD

A Reflect API request can be issued from your Gitlab CI/CD pipeline by modifying your existing .gitlab-ci.yml file:

regression_tests:
  stage: deploy
  script:
  - curl -X POST --data "{}" -H "x-api-key: <API-KEY>" https://api.reflect.run/v1/tags/<TAG-SLUG>/executions

The Reflect API key should be set as a predefined environment variable rather than hard-coded into the .gitlab-ci.yml.

For more information, check out Gitlab’s online documentation.

Jenkins Pipeline

A request to the Reflect API can be trigger via Jenkins Pipeline’s http_request plugin.

pipeline {
  stages {
    stage('Regression Test') {
      steps {
        ...
        script {
          httpRequest('https://api.reflect.run/v1/tags/<TAG-SLUG>/executions', customHeaders: [{name: 'x-api-key', value: 'API-KEY'}], requestBody: '{}')
        }
      }
    }
  }
}

For more information, please review the Jenkins Pipeline online documentation.

Travis CI

Kicking off Reflect tests after a successful deployment can be done by executing an API request in the after_deploy section of your .travis.yml file:

after_deploy:
  - "curl -X POST --data \"{}\" -H \"x-api-key: <API-KEY>\" \"https://api.reflect.run/v1/tags/<TAG-SLUG>/executions\""
Copyright © 2020 Reflect Software Inc. All Rights Reserved.