Jenkins

현시기얌·2021년 12월 8일

Jenkins

목록 보기
1/1

Jenkins

  • 오픈 소스인 자동화 서버이다.
  • 다양한 플러그인을 제공한다.
    • Pipeline
    • Authentication/Authorization
    • Git
    • Docker
  • 다양하게 확장이 가능하다.

Jenkins 설치 by docker

docker-compose.yml

docker-compose.yml 실행하기

docker-compose up -d 

만약 젠킨스 비밀번호를 입력해야 한다면??

docker exec <CONTAINER_NAME> cat /var/jenkins_home/secrets/initialAdminPassword

Jenkins pipeline

  • 젠킨스 플러그인들의 묶음
  • 소스 코드를 체크아웃, 빌드, 테스트, 스테이지 배포, 프로덕션에 배포 같이 일련의 묶음을 나타낸다.
  • Pipeline 플러그인을 설치해야 사용 가능하다.
  • CD를 서포트하기 위해 생겼다.
  • Jenkinsfile의 작업 명세서를 따른다.

Scripted pipeline

  • Groovy 스크립트를 작성할 수 있다.
  • Java API Referencing을 한다거나 JDK의 function을 호출한다거나 프로그래밍을 할 수 있다.
  • 작업의 명세가 복잡하다.

Declarative pipeline

  • Jenkins DSL을 따른다.
  • 복잡한 로직들이 Jenkins 플러그인으로 빠졌다.
  • 때문에 간단 명료하게 작성할 수 있다.

Jenkins pipeline Syntax

Section

  • agent
  • stages
  • steps
  • post

Directive

  • parameters
  • environments
  • when
  • ...

Agent : pipeline or stage가 실행될 노드를 지정한다.

위치에 따른 역할이 다르다.

pipeline 블록 바로 아래있는 글로벌 agent 설정 같은 경우에는 전체 일련의 잡들이 어떤 노드에서 실행될지를 지정하는 Section

각 stage 안에 지정되어 있는 agent 설정 같은 경우에는 스테이지만 특정 agent 노드에 실행되라는 뜻이다.

  • none
  • any : 어떤 노드들에서 실행되라
  • label : 특정 라벨이 달려있는 노드들에 작업이 실행되라
  • node
  • docker
  • dockerfile
  • kubernates

agent { label 'service || batch' } : service 또는 batch라는 라벨이 달려있는 노드를 실행해라.
agent { label 'service && batch' } : service 와 batch라는 라벨이 달려있는 노드에서만 실행해라.
agent { label 'service' } : service 라벨이 달려있는 노드에서만 실행해라.
agent { label 'batch' } : batch 라벨이 달려있는 노드에서만 실행해라.

Stage


Sections

  • Stages : 순차적인 작업의 명세인 stage들의 묶음
  • Steps : stage안에서의 실행되는 단계

Directives

  • Stage :
    • agent 설정 (optional)
    • step들의 묶음

Post

  • 위치에 따라 stages들의 작업이 끝난 후 추가적인 steps 혹은 stage에 steps들의 작업이 끝난 후 추가적인 step
  • Condition
    • always : 항상 실행
    • changed
    • fixed
    • regression
    • aborted
    • failure : 실패했을 때 실행
    • success : 성공했을 때 실행
    • unstable
    • unsuccessful
    • cleanup

environment

  • key = value
  • pipeline 내부에서 사용할 환경변수
  • credentials()를 통해 Jenkins credential에 접근 가능하다.

parameters

  • pipeline을 trigger할 때 입력 받아야할 변수를 정의한다.
  • Type
    • string
    • text
    • booleanParam
    • choice
    • password

when

  • stage를 실행 할 조건을 설정한다.

Jenkins 작업 명세

개발자가 깃허브에 푸쉬를 하면 젠킨스에서 트리거를 받아서 여러가지 잡들을 실행한다.(도커 이미지를 빌드하고 도커 레지스트리에 푸쉬하고 서버에 배포, 슬랙에 알람 등등)

profile
현시깁니다

0개의 댓글