[Jenkins] GitLab 연동

ss0510s·2024년 5월 23일
2

Infra

목록 보기
3/6

Jenkins와 GitLab 연동

💡 BackEnd와 FrontEnd 파이프라인을 분리하고, BackEnd는 Application 별로 파이프라인을 분리하여, 해당 폴더 내용이 변경되었을 때만 파이프라인이 실행되도록 독립적으로 구성한다.

[1] GitLab Access Token

  • Project -> Settings -> Project Access Tokens에서 Add new token을 통해 token 발급

[2] System → GitLab Server

  • GitLab Credential 등록 (API Token)

    • Jenkins 관리 - Manage Credentials 클릭
    • Stores scoped to Jenkins - Domains - (global) - Add credentials 클릭
    • Add Credentials 클릭
    • 정보 입력 후 Create 클릭
      • Kind : Gitlab API token 선택
      • API tokens : 위에서 발급받은 token 입력
      • ID : Credential에 대한 별칭
  • GitLab 계정 등록( Username with password)
    - Kind: Username with password

    • GitLab 계정 입력
  • Jenkins에서 System -> GitLab Server에서 아래와 같이 설정 후 test 연결시 Credentials verified for user project ~~ 나오면 성공
    - credentials는 위에서 만든 credential로 추가

[3] Item 생성

  • MultiBranch Pipeline 선택 ⇒ plugins에서 미리 설치해야함
  • Add Sources에서 GitLab Project 선택 ⇒ plugins에서 Gitlab branch source 미리 설치해야함

[4] Branch Sources

  • 위에서 설정한 server 자동 default
  • Creditional은 gitlab에 대한 username with password로 가져와짐
  • Owner은 gitlab의 소유자 → ssafy의 경우 다음과 같은 조직 형태
    ** 개인일 경우 개인 계정
  • 다 제대로 설정하면 Projects에 자동으로 가져와짐

[5] Branch 가져오기

  • Discover branches: 탐색할 branch 선택
    • Only branches that are not also field as MRs: MR로 제출되지 않은 branch만 탐색
    • Only branches that are also field as MRs: MR로 제출된 branch만 탐색
    • All branches: 모든 브런치 탐색
  • Discover merge requests from origin: mr 발견
    • Merging the merge request with the current target branch revision: 현재 branch 버전과 병합된 요청에 대해 탐색
    • The current merge request revision: 각 mr을 한번씩 발견하고, 병합하지 않은 pr head 리비전에 해당하는 리비전 검색
    • Both the current merge request revision and the merge ~~ : 현재 병합 요청된 버전과 현재 branch와 병합 요청되어 병합된 버전에 대해 탐색
  • Discover merge requests from fork: fork 된 repo에 대해 병합 요청을 탐색하는 조건에 대해 설정 ⇒ 신뢰하는 멤버인 경우 신뢰
  • 브런치 필터링을 위해 Filter by name 추가
    - filter by name(with regular expression)
    - (master|develop) 또는 (develop)
    • filter by name(with wild cards)
      • master develop
  • 폴더 필터링
    - Build strategies -> Accept build by included regions strategy -> Trigger builds for included regions 입력
    - 없으면 plugins에서 설치 필요
    • frontend, backend 분리하기 위해 frontend 폴더 변경시에만 실행되도록 함

[6] Build configuration

  • jenkinsfile 위치 설정
  • byjenkins 로 하면 gitlab의 소스파일로 관리해야하기 때문에 by default jenkinsfile로 설정하여 jenkins 내에서만 관리하도록 함 ⇒ plugins에서 설치
  • script id 설정
  • jenkis file 경로: jenkins 관리 > managed files > + add a new config
    • 위에 설정한 script id로 ID, NAME 설정 후 groovy file 생성
    • pipeline은 content에 입력

[7] Scan GitLab Project Trigger

  • cicd 트리거 설정
  • Periodically if not otherwise run : 필요한 경우 주기적인 폴백 허용
  • scan by webhoook: gitlab의 webhook과 연결
  • Gitlab에서 해당 경로로 webhook 설정
    • [jenkins url]/multibranch-webhook-trigger/invoke?token=[trigger token] 에 입력한 값
    • secret token에도 trigger token값 입력
profile
개발자가 되기 위해 성장하는 중입니다.

0개의 댓글