You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 11 Next »

Jenkins

Jenkins 개요

  • Jenkins is a free and open source automation server
  • It helps automate the parts of software development related to building, testing and deploying, facilitating continuous integration and continuous delivery

Jenkins 특징

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

Jenkins 설치 및 실행 with Docker-compose

Jenkins Pipeline of Sample

  • pipeline {
    	agent any
    	stages {
    		stage("Build") {
    			steps {
    				echo "Jenkins Pipeline running"
    			}
    		}
    	}
    }

Jenkins Pipeline

Jenkins Pipeline 개요

  • Jenkins 2.x or later (older versions back to 1.642.3 may work but are not recommended)
  • Required Plugin 'Pipeline plugin'
  • Support CD
  • Pipeline as code (DSL, Jenkinsfile)

Jenkins Pipeline Script

  • Scripted pipeline

    • inject groovy script
    • Java API reference
  • Declarative pipeline (recommended)

    • Jenkins DSL
    • Isolate complex logic into Jenkins plugin
  • Jenkins Pipeline Syntax

    • Section

      • agent
        • pipeline or stage가 실행될 노드 지정
          • node
          • any
          • label
          • node
          • docker
          • dockerfile
          • kubernetes
      • stages
        • 순차적인 작업의 명세인 stage들의 묶음
      • steps
        • stage안에서의 실행되는 단계
      • post
        • 위치에 따라 stages들의 작업이 끝난 후 추가적인 steps 혹은 stage에 steps들의 작업이 끝난 후 추가적인 step
        • Condition
          • always
          • changed
          • fixed
          • regression
          • aborted
          • failure
          • success
          • unstable
          • unsuccessful
          • cleanup
    • Directive

      • parameters
        • key = value
        • pipeline 내부에서 사용할 환경변수
        • credentials()를 통해 Jenkins credential에 접근 가능
      • environments
        • pipeline을 trigger할 때 입력 받아야 할 변수를 정의
        • Type
          • string
          • text
          • booleanParam
          • choice
          • password
      • when
        • stage를 실핼 할 조건 설정
      • ...

Jenkins Pipeline Overview

Jenkins 설치 with Docker

  • https://github.com/Sanses/devops_06_03_jenkins/blob/master/src/jenkins_remote_docker/Dockerfile

    Dockerfile
    FROM jenkins/jenkins:lts
    ARG DOCKER_GID=1000
    USER root
    
    # docker install
    COPY scripts/install_docker.sh /install_docker.sh
    RUN chmod +x /install_docker.sh && \
        /install_docker.sh
    
    # aws cli install
    COPY scripts/install_aws.sh /install_aws.sh
    RUN chmod +x /install_aws.sh && \
        /install_aws.sh
    
    # set jenkins user to host docker group
    RUN /usr/sbin/groupadd -g ${DOCKER_GID:-1000} -f docker && \
        /usr/sbin/usermod -aG docker jenkins
    
    USER jenkins
    docker-compose.yml
    version: '3.8'
    services:
      jenkins:
        build:
          context: ""
          args:
            DOCKER_GID: ${DOCKER_GID}
        container_name: jenkins
        environment:
          TZ: "Asia/Seoul"
          JAVA_OPTS: "-Dhudson.model.DownloadService.noSignatureCheck=true"
          DOCKER_GID: ${DOCKER_GID}
        ports:
          - "8080:8080"
        volumes:
          - "./data:/var/jenkins_home"
          - "/var/run/docker.sock:/var/run/docker.sock"


  • No labels