Git | GitLab

[GitLab] Runner Shell Executor - ERROR: Job failed: prepare environment: exit status 1. Check https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading for more information

비번변경 2025. 2. 19. 12:27

현상

2025.02.07-[GitLab] Runner 설치 및 등록에서 Ubuntu 22.04 LTS에서 gitlab runner를 직접 구성하여 테스트했다. shell executor를 사용하도록 구성했는데, 아래와 같은 에러 메시지가 발생하면서 동작에 실패했다.

ERROR: Job failed: prepare environment: exit status 1. Check https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading for more information

원인을 파악하고 해결해보자.

 

 

원인

에러 로그를 보면 문서를 참고하라고 되어 있는데, 문서를 확인해 보면 다음과 같이 오류 원인을 안내하고 있다.

(참고 : https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading)

 

gitlab-ci.yml에서 사용하는 bash 스크립트는 다음 명령 중 하나로 파이핑되어 실행된다.

# 다른 사용자로 실행
cat generated-bash-script | su --shell /bin/bash --login user

# 현재 사용자로 실행
cat generated-bash-script | /bin/bash --login

# 도커 환경에서 실행
cat generated-bash-script | /bin/bash

명령어에 --login 옵션이 포함되면 shell profile을 로드하기 때문에 .bashrc, .bash_logout과 같은 파일을 로드하고 실행한다. 때문에 Preparing environment 단계에서 오류가 발생하면 shell profile 파일이 원인일 수 있다.

일반적으로 .bash_logout이 콘솔을 지우려고 할 때 실패가 발생할 수 있다.

 

 

해결

공식 문서에서  안내하는 대로 조치하여 해결한다.

 

1.  /home/gitlab-runner/.bash_logout 편집

vi /home/gitlab-runner/.bash_logout

전부 주석 처리하고 저장한다. 이제 파이프라인을 다시 실행해 보면 정상적으로 동작하는 모습을 확인할 수 있다.

 

 

참고

https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading

 

 

728x90