loading...
Cover image for How debugging GitHub Actions with SSH?

How debugging GitHub Actions with SSH?

retyui profile image David Narbutovich Updated on ・2 min read

Often the best way to troubleshoot problems is to SSH into a job and inspect things like log files, running processes, and directory paths.

I really like a CircleCi ability to debugging with SSH, but seems Github Actions don't have this opportunity?

Actually no, let me show a workaround 🤪


Setup

The first step you need to create an account on the ngrok.com website

Then in the created .yml file will add a two steps:

# .github/workflows/my-build.yml
name: Debugging with SSH
on: push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
     - uses: actions/checkout@v1

     - name: Try Build
       run: ./not-exist-file.sh it bloke build

     - name: Start SSH via Ngrok
       if: ${{ failure() }}
       run: curl -sL https://gist.githubusercontent.com/retyui/7115bb6acf151351a143ec8f96a7c561/raw/7099b9db76729dc5761da72aa8525f632d8875c9/debug-github-actions.sh | bash
       env:
        # After sign up on the https://ngrok.com/
        # You can find this token here: https://dashboard.ngrok.com/get-started/setup
        # NGROK_TOKEN: ${{ secrets.NGROK_TOKEN }}
        NGROK_TOKEN: 1cu2nQXxljrX4mNGxz4z9N1QSfm_3JDS7Ek4Rti6oTwov43Sx

        # This password you will use when authorizing via SSH 
        # USER_PASS: ${{ secrets.USER_PASS }}
        USER_PASS: murAmur

     - name: Don't kill instace
       if: ${{ failure() }}
       run: sleep 1h # Prevent to killing instance after failure

NOTE: Don't paste tokens directly to .yml file
USE: Secrets variables


Result

So when the build failed will be runner SSH session and you will the next message in the console:

login command

Let login using USER_PASS: murAmur :

login via ssh
lscpu result


if you have any question I am glad to discuss them in the comments!

(c) MurAmur

Posted on by:

retyui profile

David Narbutovich

@retyui

Top 1 JS ninja 😉 by #codersrank \ React Native guru 🧘\ DevOps adjutant \ Linux lover ❤️

Discussion

markdown guide
 

Wow, that's a really smart idea. Thanks!

 

That's super helpful! Thanks, David! ✌️

Do you know a simple way to load the workflow ENV into that session?