In this tutorial, we are going to show you how to include BlazeMeter API Monitoring tests in your Codeship builds. We will use a small Python script and Trigger URLs, and we will change the build status based on the results of your test runs.
- Get Your Variables
- Set Up the Python Script
- Integrate the Script with Codeship
- Integrate with Codeship Pro
Get Your Variables
When running this script from the command line you can pass one parameter to it, which is a Trigger URL. If you want to run a single test, you can find its trigger URL under your environment settings:
If you want to run all the tests in a bucket, you can find a separate trigger URL in your bucket settings:
Make sure to copy the Trigger URL you wish to use, so we can use it with our script in the next steps.
Generate Your API Key
We need a personal access token to interact with the BlazeMeter API Monitoring API (also called Runscope API) and retrieve the results from our test run.
To get your access token, head over to your account's application tab, and click on Create Application. In the next screen, give your application a name, website URL, and callback URL. You can use dummy URLs if you're just using this app for your CI integration (e.g. http://example.org):
Click Create Application to finish the process. Then, scroll down to the bottom of your new application page and copy the personal access token value. We're going to use that in our next step:
Set up the Python Script
You can find the sample script in Heitor Sergent's GitHub:
The two files we're interested are requirements.txt and app.py. For this tutorial, we're going to work with the raw links from the GitHub repository.
If you are integrating this into your project, we highly recommend either forking it to your own repository, or adding these files to a separate folder. That way, you can prevent your build from breaking in case there's an update to the repository.
Integrate the Script with Codeship
Follow these steps:
- In your Codeship account, select the project you are working with and click Settings.
- On the left-hand side menu, click Environment. You only need to add one environment variable here named RUNSCOPE_ACCESS_TOKEN. Paste the value that you copied in our previous step for it, and click Save Configuration.
- Select Test on the left-hand side menu. The Codeship environment already comes with Python and pip pre-installed. Ensure the necessary packages for the script are installed. Add the following command to your Setup Commands window.
Note: Remember to change the requirements URL above to your fork or local file.
- Add another command just below it to download our app.py file (you can skip this step if you copied the file to your project).
- Under the Configure Test Pipelines header, in the Test Commands window, run the script. It takes one parameter, which is the Trigger URL you copied at the beginning of this tutorial. So you can just run the command as:
python app.py https://api.runscope.com/radar/your_test_trigger_id/trigger?runscope_environment=your_runscope_environment_id
Note: Remember to use the correct directory for app.py if you copied it to a folder inside your project, and change the URL after `app.py` to your tests Trigger URL.
Continuous Integration Complete
In your next build runs, you should be able to see an extra step running the Python script, and hopefully returning a green checkmark ✅:
Integrate with Codeship Pro
Codeship Pro is a more advanced offering from Codeship. It offers you more control and customization over your CI process, and includes native Docker support.
If you are using the Pro plan and want to integrate your workflow with BlazeMeter API Monitoring tests, we created a sample project that you can find here:
It's based on Codeship's tutorial project, and it includes instructions on everything you need to set it up. When you run it, it will spin up a separate container to run your Runscope API tests, in parallel to the sample Ruby application.
Having trouble configuring Codeship? Contact our Support team.