본문 바로가기

리눅스

[리눅스] jenkins gitlab 연동(webhook 설정)

728x90

jenkins gitlab 연동(webhook 설정)

gitlab 구성

.env 편집

cat <<EOF > .env
GITLAB_DOMAIN=sangchul.kr
[email protected]
EOF

docker-compose.yml 편집

cat <<EOF > docker-compose.yml
version: '3.6'
services:
  gitlab:
    env_file: .env
    image: gitlab/gitlab-ce:latest
    container_name: gitlab
    hostname: ${GITLAB_DOMAIN}
    restart: unless-stopped
    environment:
      GITLAB_OMNIBUS_CONFIG: |
          external_url 'https://gitlab.${GITLAB_DOMAIN}'
          gitlab_rails['gitlab_shell_ssh_port'] = 2222
          gitlab_rails['time_zone'] = 'Asia/Seoul'
          registry_external_url 'https://registry.${GITLAB_DOMAIN}'
          nginx['redirect_http_to_https'] = true
          nginx['redirect_http_to_https_port'] = 80
          letsencrypt['enable'] = true
          letsencrypt['contact_emails'] = ['[email protected]']
          letsencrypt['auto_renew'] = true
          letsencrypt['auto_renew_hour'] = "12"
          letsencrypt['auto_renew_minute'] = "30"
          letsencrypt['auto_renew_day_of_month'] = "*/26"
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ./gitlab/config:/etc/gitlab:rw
      - ./gitlab/data:/var/opt/gitlab:rw
      - ./gitlab/logs:/var/log/gitlab:rw
    ports:
      - 80:80
      - 443:443
      - 2222:2222
    networks:
      - gitlab

networks:
  gitlab:
EOF

gitlab에서 프로젝트 생성(apm)

gitlab에서 Access Token 발급

프로젝트 > 설정 > 액세스 토큰 > 개인 액세스 토큰 (or 프로필 > 환경설정 > 액세스 토큰 > 개인 액세스 토큰)

액세스 토큰 생성

- Token name : gitlabforjenkins

- 만료일 : 

- Select a role : 

- Select scopes : 

jenkins 구성

docker-compose.yml 편집

cat <<EOF > docker-compose.yml
version: '3.7'
services:

  jenkins:
    image: anti1346/jenkins-dood:latest
    container_name: jenkins
    restart: always
    privileged: true
    #user: root
    environment:
      TZ: "Asia/Seoul"
    volumes:
      #- /usr/bin/docker:/usr/bin/docker
      - ./jenkins_home:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - 8080:8080
      - 50000:50000
EOF

jenkins 플러그인 설치

Dashboard > Jenkins 관리 > System Configuration > 플러그인 관리

- GitLab Plugin

- Generic Webhook Trigger Plugin

Jenkins에서 gitlab에서 받은 Token 넣기

Dashboard > Jenkins 관리 > System Configuration > Manage Credentials

Credentials 설정

- Kind : GitLab API token

- Scope : Global (Jenkins, nodes, items, all child items, etc)

- API token : gitlab token

- ID : gitlabforjenkins

- Description : gitlab for jenkins

프로젝트 생성(apm project)

Enter an item name: apm project

Freestyle project

jenkins에서 자동 Build trigger 설정

jenkins 빌드 유발 설정

gitlab에서 webhook 생성

프로젝트 > 설정 > Webhooks > Webhook

gitlab webhook 설정

728x90