Run parallel jobs on Semaphore CI 2.0 to get faster CI build time
Semaphore CI 2.0 allows configuring your CI build task with parallel jobs. This way you can run simultaneously a few different commands that do not depend on each other. But we could also use parallel jobs to split your test suite across a few jobs and this way save time. I will show you how to speed up your CI build for Ruby or JavaScript project (Rails / Node project).
With Semaphore CI 2.0 you don’t pay for a reserved amount of containers that can be run in parallel as in some other CI providers. Instead, they count the amount of work time spent on running containers. This creates an incentive to run more parallel jobs to execute our tests fast and still keep bill at a similar level as if we would just run all tests in single container waisting our own time.
Let’s save time with parallel jobs
In order to run parallel jobs with our tests in an optimal way we need to ensure each job will finish work at a similar time. This way there will be no bottleneck like job executing too many tests or too slow tests. The slow job could affect and made our whole CI build slower. Especially end to end tests (E2E) can be very slow and their time execution can vary.
You can split tests across parallel jobs in a dynamic way to ensure all jobs complete work at a similar time using the Knapsack Pro Queue Mode. You can learn more about what else problems can be solved with Queue Mode in the video at the very end of this article but right now let’s jump to the Semaphore CI 2.0 demo example and the config examples we could use.
Here you can find Semaphore CI 2.0 config for projects using:
- Ruby on Rails (RSpec, other tests runners like Minitest, Cucumber and so on are also supported)
- JavaScript tests in Cypress.io end to end test runner
- JavaScript tests in Jest
Ruby on Rails config for Semaphore 2.0
knapsack_pro
gem supports environment variables provided by Semaphore CI 2.0 to run your tests. You will have to define a few things in .semaphore/semaphore.yml
config file.
- You need to set
KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC
. If you don’t want to commit secrets in yml file then you can follow this guide. - You should create as many parallel jobs as you need with
parallelism
property. If your test suite is long you should use more parallel jobs.
Below you can find full Semaphore CI 2.0 config for Rails project.
Cypress.io config for Semaphore 2.0
@knapsack-pro/cypress
supports environment variables provided by Semaphore CI 2.0 to run your tests. You will have to define a few things in .semaphore/semaphore.yml
config file.
- You need to set
KNAPSACK_PRO_TEST_SUITE_TOKEN_CYPRESS
. If you don’t want to commit secrets in yml file then you can follow this guide. - You should create as many parallel jobs as you need with
parallelism
property. If your test suite is long you should use more parallel jobs.
Below you can find example part of Semaphore CI 2.0 config.
Jest config for Semaphore 2.0
@knapsack-pro/jest
supports environment variables provided by Semaphore CI 2.0 to run your tests. You will have to define a few things in .semaphore/semaphore.yml
config file.
- You need to set
KNAPSACK_PRO_TEST_SUITE_TOKEN_JEST
. If you don’t want to commit secrets in yml file then you can follow this guide. - You should create as many parallel jobs as you need with
parallelism
property. If your test suite is long you should use more parallel jobs.
Below you can find example part of Semaphore CI 2.0 config.
The Queue Mode and summary
As you can see your CI builds can be much faster thanks to leveraging parallel jobs on Semaphore CI 2.0. You can check Knapsack Pro tool for CI parallelisation and learn more about Queue Mode and what problems it solves in below video.