기타

Jenkins - Git 연동

akatjd 2022. 4. 7. 17:19

1. git 토큰 발급

 

Github Settings -> Developer settings -> Personal access token

 

 

Note에 이름을 넣어주고 repository의 코드를 build, deploy 해야하니 전체 권한 설정.

admin:org : 프로젝트에 대한 읽기 및 쓰기 권한을 추가한다.
admin:repo_hook : repository hook에 대한 권한을 제어할 수 있다.(hook은 commit, push 등과 같은 git의 특정 이벤트 이후 실행하는 스크립트이다)

 

 

토큰값이 생성되고 해당 토큰을 잘 관리해야 함.

 

 

Jenkins -> Jenkins 관리 -> Manage Credential -> System으로 이동

 

 

 

Kind : Username with password 선택.

Username : 본인 git 아이디.

password : git에서 발급받은 personal access token 값.

ID : 원하는 값 설정. (git이 젠킨스에게 credential을 줄 때 인식함.)

 

2. git 연동

 

아이템 이름쓰고 freestyle project 설정.

 

 

github project 체크하고 url 작성.

 

public은 credentials이 필요없고 private의 경우 credentials 설정 필요.

(참조 : https://be-developer.tistory.com/15)

 

3. jenkins 관리

 

 

 

 

secret : token 입력.

ID : 고유 id 설정.

 

 

 

4. webhook 연결

 

git repository에서 webhook 들어감.

 

 

Payload URL : 젠킨스 주소/github-webhook/
Content type : application/json
trigger : push
Acive : true

 

로컬로 연결하려하면 에러발생.

 

 

개인 컴퓨터로 사용하면 포트포워딩을 진행해야함.

ngrok 설치 후 로컬 port를 열어주고 진행.

 


이건 Payload URL을 localhost로 설정 시 github의 localhost가 연결되어 나는 오류라고 한다.
도메인이 있거나, 내 개인 컴퓨터로 사용한다면 포트포워딩을 통해 진행해야 된다는..?
찾아보니 ngrok으로 진행이 가능해
ngrok을 설치해서 내 로컬의 port를 열어주고 진행했다.

(참조 : https://velog.io/@kya754/ngrok-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0)

 

 

다시 jenkins 관리 -> Global Tool Configuration

 

 

 

빌드 유발 -> Github hook 체크

 

 

clean package tomcat:redeploy -P production -D maven.test.skip=true