Automatically execute Reflect tests from within your Continuous Integration/Continuous Deployment pipeline.
Via the Reflect API, you can automatically execute tests and suites. Below we’ve outlined how to trigger a Reflect API request from within several popular CI/CD tools.
Jobs in Azure DevOps can be defined either as agentless / Server jobs or as a Pipeline job that is invoked on a remote agent.
In both cases, you’ll first need to create a Service Connection which represents the request to the Reflect API which kicks off your tests.
https://api.reflect.run/v1/suites/<suite-id>/executions
.
Replace <suite-id>
with the Suite ID on the suites page. (See Integrating via API.)See below for examples using both flavors of job definition:
|
|
|
|
For more information on Azure Pipelines jobs, please refer to Microsoft’s online documentation
To kick off Reflect tests as part of your pipeline,
you’ll need to add an additional step in your existing bitbucket-pipelines.yml
|
|
Replace <suite-id>
with the Suite ID on the suites page. (See Integrating via API.)
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.
Our recommended integration method is via the official Reflect CircleCI orb.
A minimal installation of the Reflect Orb is as follows:
|
|
Your Reflect API key should be set outside of version control as an Environment Variable rather than hard-coded in your config.yml
.
Replace <suite-id>
with the Suite ID on the suites page. (See Integrating via API.)
For detailed installation and configuration instructions, view the Reflect Orb on circleci.com.
Alternatively, you can access our API directly within your existing CircleCI to run a test suite after every deployment.
To enable automated test execution, add an additional step in your CircleCI config.yml
:
|
|
More information on calling REST APIs as part of a CircleCI build is available on the CircleCI blog.
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. Additionally, if you have OAuthed your GitHub account with Reflect, you can specify the commit SHA on your pull request to have Reflect post test results back to the pull request’s commit as the tests complete.
github.sha
instead of github.event.pull_request.head.sha
if your workflow is triggered by events other than pull-requests.
|
|
Replace <suite-id>
with the Suite ID on the suites page.
(See Integrating via API.)
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.
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
|
|
Replace <suite-id>
with the Suite ID on the suites page.
(See Integrating via API.)
A Reflect API request can be issued from your Gitlab CI/CD pipeline by modifying your existing .gitlab-ci.yml
file:
|
|
Replace <suite-id>
with the Suite ID on the suites page.
(See Integrating via API.)
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.
A request to the Reflect API can be trigger via Jenkins Pipeline’s http_request plugin.
|
|
Replace <suite-id>
with the Suite ID on the suites page.
(See Integrating via API.)
For more information, please review the Jenkins Pipeline online documentation.
Coherence is a management platform that sits atop your own cloud and
provides an integrated abstraction for development environments, preview webapps, and full-scale production deployments.
You can execute Reflect tests against your Coherence environments
by configuring an integration_test
section in the coherence.yml
file.
|
|
Replace <suite-id>
with the Suite ID on the suites page and <API-KEY>
with your Reflect API Key.
(See Integrating via API.)
You can optionally provide a POST body (using curl’s -d
flag) to specify one-time overrides for the suite execution.
For example, Coherence automatically defines an environment variable, COHERENCE_BASE_URL
,
that stores the hostname for the current Coherence environment.
You can use this environment variable to execute Reflect tests against ephemeral preview environments
by specifying a hostname override in the request body above.
(See Suite Execution Overrides.)
Finally, you may wish to store your Reflect API Key as a Coherence environment variable, and refer to that instead in the script above.
Webapp.io creates ephemeral staging environments for every Pull Request, allowing you to execute Reflect tests on every PR.
To integrate Reflect with Webapp.io, first add your Reflect API key as a SECRET ENV within your Webapp.io account.
Next, add the following shell script to your repository:
|
|
Finally, access your Reflect API key from the Settings page and invoke the shell script in your Layerfile.
(The example below assumes the file is named reflect-test.sh
.)
|
|
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:
|
|
Replace <suite-id>
with the Suite ID on the suites page.
(See Integrating via API.)
A request to the Reflect API can be made in a Task:
|
|
That Task can then be incorporated into your release Pipeline:
|
|
Replace suite-to-run
with the Suite ID on the suites page.
(See Integrating via API.)
To kick off Reflect tests after a successful deployment with Codefresh, first add your Reflect API key as a variable.
Next, add a post deploy stage to your Codefresh pipeline.
|
|
Replace <suite-id>
with the Suite ID on the suites page.
(See Integrating via API.)
Kicking off Reflect tests after a deployment can be done with a hook on the AfterAllowTraffic
lifecycle event.
For ECS and Lambda deployments, you can use a Lambda function to trigger your Reflect tests. The Lambda function can be written in whatever language you choose, calling the Reflect API with your HTTP library of choice.
Once you have a function written (named TriggerReflectTests
in this example), add the following to your AppSpec file:
|
|
An example Lambda function for CodeDeploy lifecycle events can be found here.
EC2/On-Premises deployments can specify scripts to be run on the AfterAllowTraffic
lifecycle event. To do that, add the following to your AppSpec file:
|
|
Where Scripts/PostDeploy.sh
contains:
|
|
Replace <suite-id>
with the Suite ID on the suites page.
(See Integrating via API.)
Rather than using a hook, you can use a Lambda function that is triggered by an SNS notification for your CodeDeploy deployment group on the ‘Success’ deployment event. An advantage to this approach is that you do not need to call PutLifecycleEventHookExecutionStatus in your Lambda function.
Documentation for creating an SNS trigger for a CodeDeploy deployment group can be found here.