반응형

Jenkins - Build by Git Commit
글 목적
Jenkins에서 git repository에 commit이 들어올 때마다 빌드가 자동으로 시작되도록 설정하고 싶다면 참고하세요.
사전 요구 사항
- Jenkins 설치 및 구동
- git (bare) repository 설정 완료
- Jenkins와 git repository를 연결하여 빌드 성공
과정
빌드 유발에서 “Poll SCM” 설정

git repository hook “post-receive” 설정
git repository에서 bash 파일 작성
.git/hooks/post-receive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#Example : "http://localhost:8080/git/notifyCommit?url=ssh://git@github.com/gitignore.git&branches=master" | |
curl "http://[Jenkins Address]/git/notifyCommit?url=[git repository path]&branches=[branch name]" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
while read oldrev newrev refname | |
do | |
branch=$(git rev-parse --symbolic --abbrev-ref $refname) | |
curl "http://localhost:8080/git/notifyCommit?url=http://www.projects.com/repo.git&branches=$branch" | |
done |
만약, branch 별로 post를 받고 싶다면 아래 버전 코드를 사용하면 된다.
테스트
git commit --allow-empty -m “Jenkins notify test”
git repository에 빈 내용 commit을 한다.
git push origin master
remote git에 새로운 commit을 push한다.
반응형
'KnowHow' 카테고리의 다른 글
Avast로 인해 스팀에서 몬스터헌터 월드 아이스본 실행이 안될 때 해결 방법 (0) | 2020.03.26 |
---|---|
구름 IDE에서 .NET Core 버전 업그레이드하기 (3) | 2019.05.02 |
Visual Studio를 Python IDE로 활용하기 (2) | 2017.04.30 |
꾸준히 노력하는 개발자 "김예건" 입니다.