Number of cores as env/context variable ?

Is there a general way to obtain the number of cores available on the current runner, no matter the OS ? I need to pass this number to some tools I’m using to configure parallelism.

GitHub seems has no predefined environment variables or contexts to get the number of cores.

As a workaround, you can run the following commands on each OS to view the number of cores:

On Windows:

WMIC CPU Get DeviceID,NumberOfCores,NumberOfLogicalProcessors

OR

WMIC CPU Get /Format:List

On Linux:

lscpu

OR

lscpu | egrep 'Model name|Socket|Thread|NUMA|CPU\(s\)'

On macOS:

system_profiler SPHardwareDataType

Then you can try to get the number from the output of the command, and set an output parameter with using the number as value.

In a workflow, The output parameter only can be used between the steps in a same job via the syntax  steps.<step_ID>.outputs.<output_name>. If you want to share the output parameter in other jobs, you can try to use artifact to pass the output parameter across jobs.

My reply in this ticket shows a simaple demo about how to pass variables/parameters acress jobs.

Hope this can help you.

1 Like