Sua Blog

Jenkins 설치하고 자동 배포하기

Jenkins

소프트 웨어 구축, 테스트, 배포와 관련된 모든 종류의 작업을 자동화하는 데 사용할 수 있는 오픈 소스 자동화 서버

CICD

CI

Continuous Integration 코드가 통합되는 순간에 진행돼야하는 모든것들의 자동화.

유닛 테스트, 인테그레이션 테스트, EtoE테스트, UI 테스트, 커버리지 확인, 빌드 성공여부등 마스터에 합쳐졌을때 절대로 fail 되면 안되는것들을 자동으로 확인하는 과정.

CD

Continuous Delivery Delivery는 배포를 의미하는데 Dev, Staging, Prod 모두 될수가 있고 실제 상품이 나오는단계까지 사람의 손을 최소한으로 또는 아예 안거치고 진행하는 과정

EC2(ubuntu)에 jenkins 설치하여 CICD 구현하기

apt 업데이트

apt-get update

java 8 버전 설치

sudo apt-get install openjdk-8-jdk

jenkins 저장소 키 다운로드

wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -

source list 에 추가

sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > \
/etc/apt/sources.list.d/jenkins.list'

apt 업데이트, jenkins install

sudo apt-get update
sudo apt-get install jenkins

port 변경

jenkins는 기본 8080포트를 사용하는데 나는 기존에 사용하고 있는 포트라 변경해줬다. port 변경 필요없으면 건너 뛰어도 된다.

sudo vi /lib/systemd/system/jenkins.service

27-1

jenkins 서비스 재가동, 상태 확인

sudo service jenkins restart

jenkins 서비스 상태 확인

sudo systemctl status jenkins

27-2

초기 비밀번호 확인

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

ec2 9000번 포트 열고 접속, 비밀번호 입력

27-3

플러그인 install하고 사용자 계정 만들기

27-4

Jenkins 관리 > 플러그인 관리 > ‘nodejs’ 검색 후 설치, jenkins restart

jenkins service restart

Global Tool Configuration > NodeJs > Add NodeJS > 노드 환경 생성

27-5

github repository > settings > webhooks > Add webhook

27-6

  • payloadURL: webhook post request를 받을 서버. jenkins의 경우 뒤ㅡ에 github-webhook을 명시해줘야한다.
  • content type: webhook을 어떤 형태로 받을지
  • which events would you like to trigger this webhook: push 이벤트가 발생했을 때만 webhook이 trigger되도록함

github settings > developers settings > personal access tokens > generate new token > repo check

  • token 생성 후 복사해두고 기억해두기

jenkins 관리 > Manage Credentials > (Global) > add credential

27-7

  • kind: username with password
  • scope: global
  • username: github user name
  • password: github access token
  • ID: 임의로 지은 식별자

Item 생성

새로운 Item > Freestyle project

27-8

소스 코드 관리 > Git

27-9

  • Repository URL: repository 주소
  • Credentials: 이전에 생성한 git personal access token credential

빌드 유발

Github hook trigger for GITScm polling

빌드 환경

Provide Node & npm bin/ folder to PATH

27-10

Build > Execute shell

cd /var/lib/jenkins/workspace/siso-frontend
npm install
npm run build

27-11

참고

Jenkins Documetion

https://hyunmin1906.tistory.com/272

https://blog.illunex.com/201207-2/

https://zakelstorm.tistory.com/133