DevOps

[DevOps] Jenkins Pipeline Example

차노도리 2023. 6. 27. 00:12

Jenkins Pipeline

  • Declarative
    • 구문이 간결하고 가독성이 좋다.
    • 구조와 흐름을 명시적으로 선언한다.
    • 자동으로 스테이징과 로깅을 처리한다.
  • Scripted
    • 자유로운 스크립팅이 가능하다.
    • 복잡한 로직과 동적 작업 흐름 구성이 가능하다.
    • 가독성과 유지 보수성이 낮을 수 있다.

 

 

Jenkins Pipeline Example

  • pipeline item 생성
  • pipeline script 작성

ex)

pipeline {
  ## 실행 가능한 agent 지정
  agent any   
  ## 파이프 라인 정의, 스테이지 블록 설정 영역
  stages {
    stage('Compile') {
      steps {
        echo "Compiled successfully!";
      }
    }
    stage('Code Analysis') {
      steps {
        echo "Code Analysis completed successfully!";
      }
    }
    stage('Deploy') {
      steps {
        echo "Deployed successfully!";
      }
    }
  }
  ## 파이프라인의 단계가 모두 실행된 후에 추가행되느 작업 정의 영역
  post {
    always {
      echo "This will always run"
    }
    success {
      echo "This will run when the run finished successfully"
    }
    failure {
      echo "This will run if failed"
    }
    unstable {
      echo "This will run when the run was marked as unstable"
    }
    changed {
      echo "This will run when the state of the pipeline has changed"
    }
  }
}

 

빌드 결과