Gitlab+Jenkins+Pipeline+WebHook+Multibranch - 지속적인 통합 및 자동 게시

4326 단어

[Gitlab + Jenkins + Pipeline + WebHook + Multibranch] - 지속적인 통합 및 자동 게시


본고의 실현:
  • 코드 커밋gitlab, Jenkins 빌드 자동 트리거
  • gitlab 개발 지점merge 후 dev 환경에 자동 발표
  • gitlab 마스터 분기merge 후 자동 구축,prod환경 수동 업데이트
  • Jenkins 준비
  • Jenkinsfile 준비
  • Gitlab 준비
  • Jenkins 작업 트리거 방법 선택
  • 검증
  • Jenkins 준비 작업

  • 플러그인 설치
  • gitlab
  • pipeline
  • Gitlab 연결 구성
  • 열기 - - gitlab
  • 이 옵션을 선택 해제Enable authentication for '/project' end-point
  • 구성 GitLab connections
  • 설정Connection nameGitlab host URL
  • Credentials 구성
  • Jenkins 자격 증명 추가
  • 유형 선택Gitlab API token
  • API token 가져오기
  • Gitlab에 사용자 한 명 및 개발자 역할 보유
  • 획득 방법: - User settings - Access Tokens, Token 기록을 작성
  • Token 값을 복제하여 Jenkins의 증거에 저장
  • 아래 Test Connection 테스트를 클릭
  • 성공시 알림Success
  • gitlab의 URL 주소가 정확한지 확인하지 못하면

  • 다중 분기 라인 작업 구성
  • 새 작업, 선택
  • 구성 작업
  • 창고 추가, 유형 선택Git
  • Credentials 구성
  • Jenkins 자격 증명 추가
  • 유형 선택Username with Password
  • 사용자 획득
  • Gitlab에 사용자 한 명 및 개발자 역할 보유
  • 만약 당신의 프로젝트 유형이 Private에 속한다면 이 사용자는 반드시 이 프로젝트의 구성원이어야 한다

  • 기타 기본 읽기 루트 디렉토리의 Jenkinsfile 파일
  • Jenkinsfile 준비 작업


    Jenkinsfile Demo 참조
    기본 구성:
    //   gitlab connection,         gitlab connection
    properties([gitLabConnection('gitlab-bigdata')])
    //     
    checkout scm
    //   gitlab job  
    updateGitlabCommitStatus name: 'build', state: 'pending'
    //               
    if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'dev' ) {
            stage("Build Docker Image"){
                echo "build docker image"
                echo "Only dev/master branch can build docker image"
            }
    
            if(env.BRANCH_NAME == 'dev'){
                stage("Deploy to test"){
                    echo "branch dev to deploy to environment test"
                }
    
                stage("Integration test"){
                    echo "test      "
                }
    
            }
    
            if(env.BRANCH_NAME == 'master'){
                stage("Deploy to prod"){
                    echo "branch master to deploy to environment prod"
                }
    
                stage("Health check"){
                    echo "prod  "
                }
    
            }
        }
    

    Gitlab 준비

  • 기본 보안 요청 수정
  • 주의: Jenkins와 Gitlab이 같은 기계에 있을 때
  • 루트로 로그인, - - - (Admin Area - settings - Network - Outbound requests)
  • 옵션과 함께 체크Allow requests to the local network from hooks and services, 저장

  • Jenkins 작업 트리거 방법 선택

  • 수동 트리거
  • 정시 촉발
  • Gitlab trigger
  • 프로젝트 참여Settings - Integrations
  • Jenkins 작업의 주소를 입력하고 Push eventsMerge request events
  • 를 선택합니다.
  • Jenkins URL 형식: http://JENKINS_URL/project/PROJECT_NAME
  • When you configure the plugin to trigger your Jenkins job, by following the instructions below depending on job type, it will listen on a dedicated URL for JSON POSTs from GitLab's webhooks. That URL always takes the form http://JENKINS_URL/project/PROJECT_NAME, or http://JENKINS_URL/project/FOLDER/PROJECT_NAME if the project is inside a folder in Jenkins. You should not be using http://JENKINS_URL/job/PROJECT_NAME/build or http://JENKINS_URL/job/gitlab-plugin/buildWithParameters, as this will bypass the plugin completely.
    

    확인

  • 커밋 코드
  • 상태 보기 - 프로젝트 시작
  • 웹훅 상태
  • 순차적 클릭Settings - Integrations
  • 젠킨스를 촉발시킨 기록 편집
  • 보기Recent Deliveries 부분, 최근 Trigger 상태
  • Pipelines 상태
  • Jenkins Job 상태
  • 성공 상태
  • 웹훅 상태 - 200
  • Pipelines 상태 - passed
  • Jenkins Job 상태 -

  • 감사

  • CI/CD의 Gitlab 통합 Jenkins 멀티 분기 pipeline 품질 검사 및 자동 게시
  • 좋은 웹페이지 즐겨찾기