-
Hi everyone, I am wondering because I want to fetch the statistics available in ORG > Settings > Runner-Groups for normal GH runners through the API. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
I had a similar challenge and after a bit of try and error found out following: export GH_API_BASE="https://api.github.com" # or https://github.enterprise.com/api/v3 for GitHub Enterprise Server
export GITHUB_TOKEN=ghp_abc1234 # GitHub access token with runner permissions (and org admin)
export SCALESET_ID="1" # The ID of the scaleset; can be easily seen in the URL when looking at the scaleset
export ORG="tobias-something-something" # The name of your organization
export RUNNER_REGISTRATION_URL="https://github.com/$ORG" # The URL to register runners on
export REGISTRATION_TOKEN=$(curl -u token:$GITHUB_TOKEN "$GH_API_BASE/orgs/$ORG/actions/runners/registration-token" -X POST -d '' | jq .token -r)
export PIPELINE_INFOS=$(curl -H "Authorization: RemoteAuth $REGISTRATION_TOKEN" -H "Content-Type: application/json" -d '{"url": "'$RUNNER_REGISTRATION_URL'", "runnerEvent": "register"}' "$GH_API_BASE/actions/runner-registration" -v -X POST)
export JWT_TOKEN=$(echo "$PIPELINE_INFOS" | jq -r .token)
export PIPELINE_URL=$(echo "$PIPELINE_INFOS" | jq -r .url)
curl -H "Authorization: Bearer $JWT_TOKEN" -H "Content-Type: application/json" "$PIPELINE_URL/_apis/runtime/runnerscalesets/$SCALESET_ID?api-version=6.0-preview" | jq .
{
"labels": [
{
"type": "system",
"id": 1,
"name": "my-autoscaling-set"
}
],
"createdOn": "2024-05-20T08:19:29.49Z",
"runnerSetting": {
"id": 0,
"runnerGroupId": null,
"name": null,
"version": null,
"ephemeral": true,
"status": 0
},
"runnerJitConfigUrl": "https://pipelinesghubeus14.actions.githubusercontent.com/MN2noyDyFvQtTiogzwn0iN0JT2XXios4Ew3zG4dSvsFlkTbwuH/_apis/runtime/runnerscalesets/1/generatejitconfig?api-version=6.0-preview",
"getAcquirableJobsUrl": "https://pipelinesghubeus14.actions.githubusercontent.com/MN2noyDyFvQtTiogzwn0iN0JT2XXios4Ew3zG4dSvsFlkTbwuH/_apis/runtime/runnerscalesets/1/acquirablejobs?api-version=6.0-preview",
"acquireJobsUrl": "https://pipelinesghubeus14.actions.githubusercontent.com/MN2noyDyFvQtTiogzwn0iN0JT2XXios4Ew3zG4dSvsFlkTbwuH/_apis/runtime/runnerscalesets/1/acquirejobs?api-version=6.0-preview",
"createSessionUrl": "https://pipelinesghubeus14.actions.githubusercontent.com/MN2noyDyFvQtTiogzwn0iN0JT2XXios4Ew3zG4dSvsFlkTbwuH/_apis/runtime/runnerscalesets/1/sessions?api-version=6.0-preview",
"statistics": {
"totalAvailableJobs": 0,
"totalAcquiredJobs": 0,
"totalAssignedJobs": 0,
"totalRunningJobs": 0,
"totalRegisteredRunners": 0,
"totalBusyRunners": 0,
"totalIdleRunners": 0
},
"id": 1,
"name": "my-autoscaling-set",
"queueName": "runnerscaleset-1",
"runnerGroupId": 1,
"runnerGroupName": "Default",
"enabled": true,
"status": "offline"
} Creating a ScalesetTo create a new scaleset you need to follow step 1 and 2 and then can create one using a POST request: curl -H "Authorization: Bearer $JWT_TOKEN" -H "Content-Type: application/json" "$PIPELINE_URL/_apis/runtime/runnerscalesets?api-version=6.0-preview" -d '{
"name": "my-autoscaling-set",
"runnerGroupId": 1,
"runnerSetting": {
"ephemeral": true,
"disableUpdate": true
}
}' |
Beta Was this translation helpful? Give feedback.
Deleting Scale Set
Your DELETE-request is correct. My assumption is that the JWT_TOKEN might have expired in the meantime and you need to request a new one (step 2). For me deleting the scale sets is working with this request:
Runner JIT Config
The Runner JIT config is a quite cool new addition. It allows you to create, for the specific scale set, the
.runner
,.credentials
and.credentials_rsaparams
and returns them directly. These can then be used when performing a./run.sh
of the action runner start script.The neat t…