Pinning

In high-concurrency scenarios, a runner can sometimes be “stolen” by a job other than the one that launched it, potentially leading to jobs no longer having a runner available or runners timing out before executing a job.

To ensure a runner is only assigned to the job that launched it, you can pin it to that job by adding a job pinning discriminator to the label.

This discriminator is unique and shared by both the job and its runner and ensures they are always matched together. The easiest way to do this would have been to use the job’s unique ID, but unfortunately, GitHub doesn’t let you access that from within the workflow yml. We can however achieve the same result by combining various job attributes, depending on whether the job is a regular job, a matrix job or a reusable workflow job.

Regular Jobs

The following attributes uniquely identify a regular job:

Attribute Description
github.run_id The unique ID of the current workflow run.
github.run_attempt The attempt number of the current workflow run.
job_name The name of the current job.

The job pinning discriminator would therefore be ${{ github.run_id }}-${{ github.run_attempt }}-job_name

Simply add it as an additional label (all variables will be replaced at runtime):

Your regular job will now be pinned to the correct runner.

Matrix Jobs

The following attributes uniquely identify a matrix job:

Attribute Description
github.run_id The unique ID of the current workflow run.
github.run_attempt The attempt number of the current workflow run.
job_name The name of the current job.
strategy.job-index The position of the job within the matrix.

The job pinning discriminator would then be ${{ github.run_id }}-${{ github.run_attempt }}-job_name-${{ strategy.job-index }}

Simply add it as an additional label (all variables will be replaced at runtime):

Your matrix job will now be pinned to the correct runner.

Reusable Workflow Jobs

The following attributes uniquely identify a reusable workflow job:

Attribute Description
github.run_id The unique ID of the current workflow run.
github.run_attempt The attempt number of the current workflow run.
job_name The name of the current job.
inputs.param1 The inputs that uniquely distinguish this call of the reusable workflow.
inputs.paramN The inputs that uniquely distinguish this call of the reusable workflow.

The job pinning discriminator would then be ${{ github.run_id }}-${{ github.run_attempt }}-job_name-${{ inputs.param1 }}-${{ inputs.paramN }}

Simply add it as an additional label (all variables will be replaced at runtime):

Your reusable workflow job will now be pinned to the correct runner.

Need help? We’re here for you at [email protected]

What's new? · Pricing · Docs · Security


© 2025 InfrastructureX GmbH
Terms of Service · Privacy Policy · Impressum
Sprinters is a registered trademark of InfrastructureX GmbH
Made with ♥️ in München