Accessing the node index of a concurrent Gitlab runner
The Gitlab CI attribute parallel allows to easily split your test parcour in chunks allowed to run in parallel (some frameworks call this test sharding).
For this, your test environment then has the environment variables CI_NODE_INDEX
and CI_NODE_TOTAL
available telling it which chunk of the test suite should be run. These jobs then pick available runners to be executed.
We need similar environment variables available for Runners. The concurrent
runner attribute allows to define how many instances of one runner configuration are allowed to run in parallel on a single machine. We need a way to determine on which index the current test is running on.
Use case (for clarification)
- I want to use the test sharding to split my on-device Android tests in multiple chunks to run in parallel. Let's say I want it to be 2 chunks.
- I use a shell runner with concurrency=4
- The runner has to start an Android emulator for the tests on a known, unique network port so it is configurable and controllable.
If I now use the CI_NODE_INDEX
as emulator port* , I will run into problems. As I have four concurrent runners on one machine, two separate pipelines with each two parallel chunks can run. In both pipelines, the chunks will have the node indices 0 and 1, meaning the two pipelines try to use the same emulator.
I'd rather need to know the index of the concurrent runner - which at least when looking at runner logs, seems to be known to the runner itself.
Proposal:
Two new variables CI_CONCURRENT_INDEX
and CI_CONCURRENT_TOTAL
*(this is a simplification, as the Android emulator needs an even port to be configured. But let's ignore this for now)