UPDATE: 27.10.2020
Thanks Luchi, who create a GitHub Action debug-via-ssh now it easier to connect into an instance.
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
- The script that start a ssh session
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:
Let login using USER_PASS: murAmur
:
if you have any question I am glad to discuss them in the comments!
(c) MurAmur
Top comments (6)
Any way to debug
runs-on: windows-latest
?I've also needed a way to debug Windows GitHub Actions runners and ended up making github.com/marketplace/actions/deb...
Any feedback or code contributions are extremely welcomed!
Actually, I haven't investigated for work with ssh on Windows and I can't give advice
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?
Just login in Linux container and write next commands: