Setup a Self Hosted GitHub Runner with Support for SonarCloud

Copenhagen based cloud developer. Love to code and to make complex solutions simple!
Search for a command to run...

Copenhagen based cloud developer. Love to code and to make complex solutions simple!
No comments yet. Be the first to comment.
And examples for .NET projects also

...and why Windows is not going to sleep when left idle

TL;DR Keep trying the firmware update - after around 30 attempts doing the same thing, it just worked 🤯🎉🪅 Awesome Ultrawide Monitor, not only for gaming For once I'm going to write an article which is not directly related to programming, but if yo...

...and some SonarCloud code analysis!

When using GitHub actions it's pretty neat that you can use the hosted GitHub runners. However, this can get costly if you use a lot of runners and they are not always that fast at running the actions.
Luckily you can also host your own runners and while this is pretty straight forward, in case you use SonarCloud there are a few problems, read on to see how to solve those.
You can set up a GitHub Runner on organization level or on a repository. Here we are going to set it up on an Organization level.
https://github.com/organizations/YOUR-ORGANIZATION/settings/actions/runnersNew runnerYou should see something like this:

For your GitHub Actions to use your runner, remember to change the runs-on to self-hosted
If you are using GitHub Actions to do SonarQube analysis of your source code you will most likely get an error when using a self-hosted runner due to the fact the SonarQube need to use PowerShell scripts to run on your runner machine. Here's an example of how the error can look like:
D:\actions-runner-001\_work\_temp\3a394734-81e3-4f27-b06e-d3bcea4ecd4a.ps1 is not digitally signed. You cannot run
this script on the current system. For more information about running scripts and setting execution policy, see
about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
There is a open issue on Github but luckily there's also a fix in the comments, here's what it says:
psexec -i -u "nt authority\network service" powershell.exeSet-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUserWith that fix in place you should be able to run the action and in SonarCloud (or SonarQube if you have it hosted on-prem), you will start seeing results like this:
