Working with scheduled CircleCI pipelines can sometimes be cumbersome. In this blog post, we will learn how Postman can supercharge your experience with CircleCI pipelines, particularly with scheduled pipeline runs.
Let’s go over the problems and solutions when working with scheduled CircleCI pipelines.
Limitations associated with scheduled CircleCI pipelines
Imagine you want to schedule your CircleCI pipeline to run at midnight for your nightly workflow (test run). Below is the code snippet of how you could schedule that in CircleCI config.yml:
There is nothing wrong with this: The pipeline run will start on time, and you will have your scheduled run fully functioning. However, what if you want to change the schedule? What if you want to modify the cron pattern?
You would need to make changes in the pipeline’s config.yml file, commit the changes, push to a remote repository, raise a pull request, get approval, and finally merge your changes. Sigh. That can be a long way to go. Now, what if you have multiple scheduled workflows and you want to make changes in several workflow schedules? This is not an easy or fast task to achieve.
So how can you avoid this endless loop of a pipeline configuration change, commit, merge, etc.? The best way is to use Postman monitors in conjunction with CircleCI.
How to trigger a CircleCI pipeline via API request in Postman
CircleCI provides some handy APIs for those who want to run pipelines programmatically. First, let’s look at what you need to change in the config.yml file to make maximum use of APIs.
As you can see in the above image, we have removed the hard-coded schedule logic from the config.yml file because we are going to trigger the pipeline run through an API call. Instead, we implemented a conditional logic with the help of CircleCI pipeline parameters so that the nightly workflow will run only when we provide the
run_nightly_tests parameter inside our API request body with a Boolean value equal to
true. Why is this necessary? Because if we don’t implement conditional logic for our workflow, it will run upon every code commit, which we don’t want.
If you want to dive deeper, here is the full configuration config.yml file:
Below is the API request inside a Postman Collection named Run CircleCI Pipeline:
You can see that the API request body contains information about the
branch on which we want to execute our nightly tests and also the required parameter to trigger the nightly test run workflow
What about the URL? We need to specify the version control system (VCS), username or organization name, and the VCS repository name. You can find detailed guidelines about how to construct the URL of the request and all requirements in the official documentation of CircleCI API.
Note: You need to have
CIRCLECI_PERSONAL_TOKEN set up through your CircleCI project and include that token in the API request header as shown below:
Now, when our API request is ready, we can send it and see in CircleCI that it triggers the pipeline run:
So far, we’ve figured out how to trigger pipelines through API requests, but we still have to set up our desired schedule. We are almost there!
How to schedule a CircleCI pipeline run with Postman monitors
Postman’s monitoring service allows you to monitor API health, performance, schedule monitor runs for collections, perform continuous testing, integrate monitors with third-party services such as Slack, Opsgenie, Datadog, and more.
Let’s create a monitor for our Run CircleCI Pipeline collection, which contains our API request:
Select the collection from the Collection drop-down and specify the desired schedule for the monitor: In this case, select every day at midnight.
Run the monitor, and it will again trigger the same nightly test pipeline run in CircleCI.
You can now move on and modify the monitor schedule however you want with the wide variety of options that the Postman monitoring service allows—and all that without changing a single line of configuration in the CircleCI config.yml file. Congratulations, now you have a graphical user interface (GUI) for your scheduled pipeline.
4 key advantages of Postman monitors
Here is a summary of several crucial advantages of using Postman monitors for running CircleCI pipelines:
- Easy, fast, and flexible schedule maintenance. With the help of Postman monitor schedules, you can now just edit a monitor and choose whatever schedule you want for your pipeline instead of making changes in the pipeline configuration file, committing changes, etc.
- Postman monitor graphs allow you to visualize your monitor runs, which means that you can see when and how many times your pipeline was triggered.
- Postman allows you to select “Pause” or “Resume” monitors, which means that you can pause or resume CircleCI pipelines. This is an entirely new feature that is only possible if you use Postman monitors because CircleCI does not completely support it on its own.
- With the help of the Postman Monitor API, you can run your monitor with just a single API call. In comparison with the CircleCI API request, where we provided our
branchin the request body, you don’t need to specify anything for monitor run. Just a single POST request with an empty payload, and your monitor/pipeline is running.
In this post, we saw how extremely convenient it is to work with CircleCI pipelines using Postman—especially with Postman monitors. Postman monitors not only allow you to schedule pipeline runs in a fast and easy way, but they also provide a completely new feature of pausing or resuming pipelines, giving you more power over your CI processes and testing.
What do you think about this topic? Tell us in a comment below.