레이블이 pipeline인 게시물을 표시합니다. 모든 게시물 표시
레이블이 pipeline인 게시물을 표시합니다. 모든 게시물 표시

jenkins multibranch pipeline 환경 설정

# 우선 github 계정에 personal access token 을 생성한다.
settings -> developer settings -> personal access token 에서
scopes 선택시, repo 권한 admin:repo_hook 권한을 체크한다.

# jenkins multibranch pipeline 사용하기
# 다음 플러그인들을 설치 한다.
Blue Ocean : 파이프라인 작성을 UI 적으로 사용(관련 플러그인들이 함께 설치된다.)
Pipeline: Stage View Plugin
GitHub API Plugin
GitHub Authentication plugin
GitHub Branch Source Plugin
GitHub Pipeline for Blue Ocean
GitHub plugin

# API endpoint : jenkins 관리 -> 시스템설정 에서 다음 항목을 설정해야 한다.
# github github servers -> api urls
api urls : https://developer.github.com/v3/

# github github servers -> credentials
# github 저장소 접근 id, pw(personal access token) 으로 추가.
# 추가 후 해당 credential 의 ID(123-456-789) 값을 jenkinsfile 에 명시한다.
environment {
   ysoftman = credentials('123-456-789')
}

# github enterprise servers -> api endpoint
api endpoint : https://developer.github.com/v3/
name : ysoftman github

# multibranch pipeline 생성
jenkins -> new item -> multibranch pipeline : ysoftman_multibranch_pipeline

# github 브랜치 설정
# ysoftman_multibranch_pipeline -> configure -> branch sources
# API endpoint : 위 시스템 설정에한 넣은 값 선택
# Credentials : 위 시스템 설정에한 넣은 값 선택
# Owner : https://github.com/ysoftman/test_code 의 경우 ysoftman
# Repository : owner 의 저장소 리스트를 볼 수 있고 이중 하나를 선택할 수 있다.
# Behaviours : 선택한 저장소의 All branches 를 스캔할 수 있다.


# orphaned item strategy -> discard old item 을 선택하면 삭제된 브랜치나 태그들은 모두 파이프라인에서 바로 제거 된다.
# 아래 처럼 유지 기간을 입력하면 삭제 되더라도 7일까지만 유지하고 지나면 삭제한다.
# 참고로 0 값은 설정할 수 없고 빈값으로 설정해야 바로 제거 된다.
# Days to keep old items: 빈값
# Max # of old items to keep: 빈값


# 파이프라인 스크립트(jenkinsfile) 작성
# jenkinsfile 는 groovy(자바동작타입스크립트언어)사용 스크립트 사용한다.
# jenkinsfile 파일 작성방법
https://jenkins.io/doc/book/pipeline/

# 스크립트에 문제가 있다면 다음과 같은 에러가 발생한다.
GitHub has been notified of this commit’s build result
java.lang.NoSuchMethodError: No such DSL method 'cleanWs' found among steps

# 위 에러 예시는 cleanWs() 함수를 사용할수 없는 경우로
# Workspace Cleanup Plugin 플러그인을 설치해야 한다.

# 참고로 jenkinsfile 은 에러가 있을 경우
# build history -> replay 에서 스크립트를 수정해 테스트할 수 있다.
# 테스트 후 문제가 없다면 github 저장소로 커밋/push 하자.