강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

lucky5632님의 프로필 이미지
lucky5632

작성한 질문수

Jenkins를 이용한 배포 중 깃허브 연결 인증 문제

작성

·

790

·

수정됨

0

안녕하세요 jenkins를 이용해서 배포를 하려고 강의를 들으면서 진행중에 있습니다.

잘 따라하던 중 강의와는 다른 오류가 떠서 해결하려 했으나 여전히 같은 오류가 뜹니다

Started by user ***
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/jenkins_home/workspace/lymming-url-deploy
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Tool Install)
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Checkout)
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] withEnv
[Pipeline] {
[Pipeline] git
The recommended git tool is: NONE
using credential 310a0522-2bcc-4cad-8254-ffd41ab6262d
 > git rev-parse --resolve-git-dir /var/jenkins_home/workspace/lymming-url-deploy/.git # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url git@github.com:supernova-3/Supernova-BackEnd.git # timeout=10
Fetching upstream changes from git@github.com:supernova-3/Supernova-BackEnd.git
 > git --version # timeout=10
 > git --version # 'git version 2.39.2'
using GIT_SSH to set credentials 
[INFO] Currently running in a labeled security context
 > /usr/bin/chcon --type=ssh_home_t /var/jenkins_home/workspace/lymming-url-deploy@tmp/jenkins-gitclient-ssh11595399119115108828.key
Verifying host key using known hosts file
You're using 'Known hosts file' strategy to verify ssh host keys, but your known_hosts file does not exist, please go to 'Manage Jenkins' -> 'Security' -> 'Git Host Key Verification Configuration' and configure host key verification.
 > git fetch --tags --force --progress -- git@github.com:supernova-3/Supernova-BackEnd.git +refs/heads/*:refs/remotes/origin/* # timeout=10
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from git@github.com:supernova-3/Supernova-BackEnd.git
	at PluginClassLoader for git//hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:997)
	at PluginClassLoader for git//hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1239)
	at PluginClassLoader for git//hudson.plugins.git.GitSCM.checkout(GitSCM.java:1303)
	at PluginClassLoader for workflow-scm-step//org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:136)
	at PluginClassLoader for workflow-scm-step//org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:101)
	at PluginClassLoader for workflow-scm-step//org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:88)
	at PluginClassLoader for workflow-step-api//org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- git@github.com:supernova-3/Supernova-BackEnd.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: No ED25519 host key is known for github.com and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

	at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2846)
	at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2185)
	at PluginClassLoader for git-client//org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:635)
	at PluginClassLoader for git//hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:995)
	... 11 more
ERROR: Error fetching remote repo 'origin'
ERROR: Maximum checkout retry attempts reached, aborting
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build)
Stage "Build" skipped due to earlier failure(s)
[Pipeline] getContext
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Deploy)
Stage "Deploy" skipped due to earlier failure(s)
[Pipeline] getContext
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] echo
Deployment failed.
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE


강의에서는 pipeline script를
pipeline {

agent any

tools {

maven "M3" // Jenkins에서 설정한 Maven의 이름

}

stages {

stage('Checkout') {

steps {

git url: 'https://github.com/lleellee0/deploy-test', branch: 'main'

}

}

 

stage('Build') {

steps {

script {

sh 'mvn clean package'

}

}

}

 

stage('Deploy') {

steps {

script {

// Maven 빌드로 생성된 jar 파일의 위치

def jarFile = 'target/shortenurlservice-0.0.1-SNAPSHOT.jar'

// 원격 서버의 IP 주소 및 배포 경로

def serverIp = 'xxx.xxx.xxx.xxx'

def deployPath = '/root'

def runAppCommand = "java -jar $deployPath/shortenurlservice-0.0.1-SNAPSHOT.jar"

 

// 서버에 파일을 SCP로 전송

sh "scp -o StrictHostKeyChecking=no $jarFile root@$serverIp:$deployPath/"

 

// 원격 서버에서 애플리케이션 실행

sshagent(['deploy_ssh_key']) { // 'server-ssh-credentials'는 Jenkins에서 설정한 credentials ID

sh "ssh -o StrictHostKeyChecking=no root@$serverIp '$runAppCommand'"

}

}

}

}

}

 

post {

success {

echo 'Deployment was successful.'

}

failure {

echo 'Deployment failed.'

}

}

}
이렇게 설정하였으나 저는 제가 만든 프로젝트와 깃허브 레포지토리가 있어 git url부분을 제 레포지토리 주소로 변경했더니 뜬 오류입니다.

인증 방식에 문제가 있는것 같아 ssh로 깃허브 ssh와 jenkins ssh에

putty로 접속한 .ssh 즉 root@jenkins instance에서 publickey와 privatekey를 발급해 설정했음에도 jenkins에서 지금 빌드 버튼을 누르면 같은 오류가 발생하면서 빌드가 되지 않습니다.

구글 서치를 통해 이것저것 시도도 해보고 설정도 다시 해봤으나
github의 webhook에서 보면 설정이 잘 된거같은데

왜 자꾸 인증 오류가 뜨면서 ERROR: Error fetching remote repo 'origin' 이 오류가 뜨는건지 모르겠습니다.

답변 1

0

안녕하세요, 인프런 AI 인턴입니다.

Jenkins를 사용하여 GitHub 레포지토리와 연결할 때 발생하는 인증 문제는 여러 원인에 의해 발생할 수 있습니다. 제시하신 로그와 내용을 바탕으로 몇 가지 가능한 해결 방안을 제안드립니다.

  1. Known Host 파일 설정: Jenkins에서 GitHub로의 SSH 연결 시 “known_hosts” 파일이 없다거나, GitHub 서버의 호스트 키가 “known_hosts” 파일에 없을 때 발생하는 문제입니다. Jenkins 시스템 내의 “~/.ssh/known_hosts” 파일에 GitHub의 호스트 키를 추가해주어야 합니다. 이를 위해 Jenkins 서버에서 GitHub을 SSH로 처음 연결할 때 생성되는 호스트 키를 수동으로 “known_hosts” 파일에 추가하거나, 해당 키를 자동으로 수락하도록 설정해야 합니다.

  2. SSH 키 권한 설정: Jenkins에서 사용하는 SSH 키의 권한 문제일 수도 있습니다. 보안상의 이유로, SSH 프라이빗 키는 오직 소유자만이 읽을 수 있어야 합니다. 키의 권한을 chmod 600 /path/to/private_key 명령어를 사용하여 확인하고 수정하십시오.

  3. Credentials 설정 확인: Jenkins에서 GitHub로 접속하기 위해 사용하는 Credentials(인증 정보) 설정이 올바른지 확인 필요합니다. Jenkins 대시보드의 “관리 메뉴”에서 Credentials 설정을 다시 확인하고, 해당 SSH 키가 GitHub 계정에 등록되어 있으며 Jenkins에서도 동일한 키를 사용하고 있는지 확인해야 합니다.

  4. SSH URL 대신 HTTPS URL 사용: 현재 SSH URL(git@github.com:supernova-3/Supernova-BackEnd.git)을 사용하고 계시는데, 이를 HTTPS URL(https://github.com/supernova-3/Supernova-BackEnd.git)으로 변경해 보시는 것도 한 가지 방법입니다. Jenkins에서 HTTPS 방식을 사용할 경우, 별도의 SSH 키 설정 없이 GitHub의 Personal Access Token을 사용하여 인증할 수 있습니다.

해당 문제를 해결하기 위해 위의 제안들을 차례대로 시도해 보시기 바랍니다. 만약 문제가 여전히 해결되지 않는다면, 좀 더 구체적인 설정 상황(예: Jenkins의 Credentials 설정 화면, SSH 키 설정 상태 등)을 제공해 주시면 더 정확한 해결책을 제공해 드릴 수 있을 것입니다.

lucky5632님의 프로필 이미지
lucky5632

작성한 질문수

질문하기