Self-hosted runners API - Unprocessable Entity

Hi! 

I’m working on automated self-hosted runner configuration and I have a strange case of runner’s registration exception:

  1. Run Create registration token method of github API

  2. Pass token from the response to config.sh

  3. Runner authentication fails with message

    Http response code: UnprocessableEntity from ‘POST https://api.github.com/repos/myorganization/myproject/actions-runners/registration
    {“message”:“Validation Failed”,“documentation_url”:“https://developer.github.com/v3”}
    Response status code does not indicate success: 422 (Unprocessable Entity).
    An error occurred: Not configured

This error does not reproduce if I push the button Add runner from project settings before any  API calls. After pushing this button runner authentication works pretty well event with tokens generated with API. For me it looks like this button also changes some flag in project settings.

Is there any logic in this behavior?

1 Like

@fisherking 

Can you share the detailed steps and scripts you are using to create the registration token and install the self-hosted runner?

I tested with the following scripts on Windows with PowerShell, and it can work fine as expected:

## Create the registration token ##
$pat = <GitHub_PAT>
$uri = "https://api.github.com/repos/<org_name>/<repo_name>/actions/runners/registration-token"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "", $pat)))

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", ("Basic {0}" -f $base64AuthInfo))
$headers.Add("Content-Type", "application/json")

$response = Invoke-RestMethod -Uri $uri -Headers $headers -Method POST
$reg_token = $response.token
echo "The registration token is $reg_token"

## Create and switch to the installation directory of the self-hosted runner ##
mkdir <installation_directory>;cd <installation_directory>

## Install the self-hosted runner ##
Invoke-WebRequest -Uri https://github.com/actions/runner/releases/download/v2.165.2/actions-runner-win-x64-2.165.2.zip -OutFile actions-runner-win-x64-2.165.2.zip
Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD/actions-runner-win-x64-2.165.2.zip", "$PWD")
./config.cmd --url <repo_url> --token $reg_token --agent <runner_name> --work <work_dir> --runasservice

@brightran have you added runners manually for the same repo before? I can add more details to my testcase:

  1. Run  Create registration token  method of github API

  2. Pass token from the response to config.sh

  3. Runner authentication fails with message

    Http response code: UnprocessableEntity from ‘POST https://api.github.com/repos/myorganization/myproject/actions-runners/registration
    {“message”:“Validation Failed”,“documentation_url”:“https://developer.github.com/v3”}
    Response status code does not indicate success: 422 (Unprocessable Entity).
    An error occurred: Not configured

 4. Push button Add runner in repo settings

 5. Next run of config.sh works fine even with previous token without any additional actions

This definetely means that  Add runner button also changes some state and allows you to use API for registering runners (which is not possible without pushing this button). You can reproduce this behaviour if you try with fresh new repository for example.

1 Like

@fisherking ,

Yes, I had manually added some self-hosted runners in the same repository before.

I created a new repository and did not click the Add runner button, then tried the steps as you shared, and I can reproduce the same issue as you reported.

Looks like, some things changed to allow the generated token can be used to install the self-hosted after clicking the Add runner button. This is very strange.

I have reported this issue to the appropriate engineering team, they will evaluate and investigate the issue. If they have any update, I will notify you in time, and sometimes the appropriate engineers may also will directly reply you here.

Anyone found a solution to this? I’m running into this when trying to automate self-hosted runners.

Also, just opened this issue: https://github.com/actions/runner/issues/487