젠킨스 파이프라인
코드로서의 파이프라인을 지원하는 기능
빌드, 테스트, 배포 등의 소프트웨어 개발 프로세스를 코드로 정의할 수 있게 한다.
파이프라인의 주요 구성 요소
Pipeline
pipeline { ... }
Agent: 파이프라인의 각 단계를 실행할 노드를 정의한다.
any
라면 가용한 모든 에이전트에서 실행된다agent any
Stages: 파이프라인을 여러 단계로 나눈다. 각 단계는 특정 작업 (빌드, 테스트, 배포 등)을 수행한다
stages { stage('Build') { steps { echo 'Building...' } } stage('Test') { steps { echo 'Testing...' } } stage('Deploy') { steps { echo 'Deploying...' } } }
Steps: 각 단계에서 실행될 구체적인 명령어를 정의한다
steps { echo 'Hello, World!' }
실습
- 오른쪽에 Hello world 선택하기
- 단계 생성
만약에 한 단계가 실패했다고 하면
- 이런 식으로 어느 단계에서 실패했는지 pipeline의 형태로 볼 수 있음
- 앞 단계가 실행되지 않았다면, 뒤에도 실행하지 않음
pipeline {
agent any
stages {
stage('Compile') {
steps {
echo "Compiled successfully!";
}
}
stage('Test') {
steps {
echo "Test passed successfully!";
}
}
stage('Code Analysis') {
steps {
echo "Code Analysis completed successfully!";
}
}
stage('Deploy') {
steps {
echo "Deployed successfully!";
}
}
}
}
- 보통 위와 같이 Compile, Test, Code Analysis, Deploy 형식의 배포 절차를 가짐
Pipeline StageView 플러그인 설치
pipeline {
agent any
stages {
stage('Compile') {
steps {
echo "Compiled successfully!";
}
}
stage('Test') {
steps {
echo "Test passed 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"
}
}
}
complie을 error 처리 했을 때
대표적인 Directive (지시자)
Directive | 설명 |
---|---|
node | Scripted 파이프라인을 실행하는 젠킨스 에이전트 최상단 선언 필요, 젠킨스 마스터-슬레이브 구조에서는 파라미터로 마스터-슬레이브 정의 가능 |
dir | 명령을 수행할 디렉토리 / 폴더 정의 |
stage | 파이프라인의 각 단계를 얘기하며, 이 단계에서 어떤 작업을 실행할지 선언하는 곳(즉, 작업의 본문) |
git | Git 원격 저장소에서 프로젝트 Clone |
sh | Unix 환경에서 실행할 명령어 실행. 윈도우에서는 bat |
def | Groovy 변수 혹은 함수 선언 |
'DevOps🚚 > Jenkins' 카테고리의 다른 글
[Jenkins][KDT 2차 프로젝트] Jenkins Pipeline : Rolling (0) | 2024.08.23 |
---|---|
[Jenkins] Rolling, Blue/Green 배포 (0) | 2024.08.23 |
[Jenkins] [KDT 2차 프로젝트] WebHook 설정 (0) | 2024.08.23 |
[Jenkins][KDT 2차 프로젝트] Pipeline 단순 배포 (0) | 2024.08.23 |
[Jenkins] 깃 클론해서 Pipeline 구축하기 (0) | 2024.08.23 |