작성
·
62
·
수정됨
1
학습 도중 발견한 내용이 있어 공유합니다. appleboy/ssh-action 라이브러리에서 stop_script
설정에 대한 내용입니다. 결론부터 말하면, appleboy/ssh-action 최신 버전(작성일 기준 1.2.2)을 사용하는 경우 stop_script: true
대신 script
첫 줄에 set -e
를 사용해야 합니다.
script: |
set -e
cd /home/ubuntu/github-actions
git pull origin main
강의를 따라하던 중, 테스트에서 RuntimeException
을 던져 실패하는 부분에서 다음과 같이 빌드는 실패하는데 github actions가 성공하고 코드도 업데이트 되는 경우가 발생했습니다. deploy.yml
과 github actions
결과는 다음과 같습니다.
name: hello application
on:
push:
branches:
- main
jobs:
Deploy:
runs-on: ubuntu-latest
steps:
- name: ssh to EC2
uses: appleboy/ssh-action@v1.2.2
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
script_stop: true
script: |
cd /home/ubuntu/github-actions
git pull origin main
./gradlew clean build
sudo fuser -k -n tcp 8080 || true
nohup java -jar build/libs/*SNAPSHOT.jar > ./output.log 2>&1 &
> Task :test
GithubActionsApplicationTests > contextLoads() FAILED
java.lang.RuntimeException at GithubActionsApplicationTests.java:11
1 test completed, 1 failed
FAILURE: Build failed with an exception.
> Task :test FAILED
* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///home/***/github-actions/build/reports/tests/test/index.html
* Try:
> Run with --scan to get full insights.
BUILD FAILED in 8s
8 actionable tasks: 8 executed
8080/tcp:
4782
===============================================
✅ Successfully executed commands to all hosts.
===============================================
이 차이점은 appleboy/ssh-action 버전을 최신 버전(1.2.2)으로 사용한 차이에서 발생한 것이었습니다. appleboy/ssh-action 링크에 가서 script_stop
으로 검색해보니 다음과 같은 부분이 있습니다.
1.0.3v 를 보니 해당 옵션이 있는 걸로 보아 script_stop
옵션은 제거된 것으로 보입니다. 그래서 적힌대로 set -e
를 script
첫 줄에 추가했습니다.
script: |
set -e
cd /home/ubuntu/github-actions
git pull origin main
이후 다시 푸시해보니 정상적으로 실패하는 것을 확인할 수 있습니다.
1 test completed, 1 failed
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///home/***/github-actions/build/reports/tests/test/index.html
* Try:
> Run with --scan to get full insights.
GithubActionsApplicationTests > contextLoads() FAILED
java.lang.RuntimeException at GithubActionsApplicationTests.java:11
BUILD FAILED in 8s
8 actionable tasks: 8 executed
2025/07/12 14:16:36 Process exited with status 1
Error: Process completed with exit code 1.
답변 2
0
안녕하세요 재현님!! 좋은 내용 공유해주셔서 너무 감사드립니다~!
공유해주신 내용 덕분에 다른 수강생분들도 도움 많이 받으실 수 있을 것 같네요!
저도 말씀해주신 내용 참고해서 수업 자료도 이번 주 중으로 보완해두겠습니다:D
0
안녕하세요, 인프런 AI 인턴입니다. 한재현님.
“appleboy ssh-action”과 관련된 문제와 해결 방법에 대해 자세한 설명을 공유해주셔서 감사합니다. 실제로 많은 사용자들이 script_stop
옵션의 차이를 경험하고 있습니다. 해당 옵션이 최신 버전에서 제거되어, set -e
명령어를 사용하여 스크립트의 중단을 처리해야 합니다.
GitHub Actions에서 RuntimeException
이 발생했음에도 불구하고 빌드가 지속되고 성공으로 표시되는 문제를 경험하신 상황이었네요. 이는 script_stop: true
옵션이 최신 버전에서는 제거되었기 때문입니다. 이로 인해 스크립트가 오류 발생 시 즉시 중단하는 기능이 설정되지 않았던 것입니다.
set -e
를 사용해 이 문제를 해결할 수 있습니다. set -e
는 스크립트 내에서 오류가 발생하면 즉시 종료하도록 하여, 오류가 발생할 경우 전체 워크플로우가 실패로 처리되도록 보장합니다. 다음과 같이 사용하면 됩니다:
script: |
set -e
cd /home/ubuntu/github-actions
git pull origin main
set -e
명령어는 Bash 스크립트에서 에러가 발생했을 때 자동으로 스크립트를 중단시켜 오류를 처리하도록 돕습니다.관련 내용을 확인할 수 있는 링크는 아래를 참고해주세요:
- Appleboy Github Actions SSH Action 사용 예시
저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.