[Jenkins] Pipeline

Na young·2024년 7월 10일
0

Jenkins

목록 보기
2/4

젠킨스 파이프라인

코드로서의 파이프라인을 지원하는 기능
빌드, 테스트, 배포 등의 소프트웨어 개발 프로세스를 코드로 정의할 수 있게 한다.

파이프라인의 주요 구성 요소

  1. Pipeline
pipeline {
    ...
}
  1. Agent: 파이프라인의 각 단계를 실행할 노드를 정의한다. any라면 가용한 모든 에이전트에서 실행된다
agent any
  1. Stages: 파이프라인을 여러 단계로 나눈다. 각 단계는 특정 작업 (빌드, 테스트, 배포 등)을 수행한다
stages {
    stage('Build') {
        steps {
            echo 'Building...'
        }
    }
    stage('Test') {
        steps {
            echo 'Testing...'
        }
    }
    stage('Deploy') {
        steps {
            echo 'Deploying...'
        }
    }
}
  1. 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설명
nodeScripted 파이프라인을 실행하는 젠킨스 에이전트 최상단 선언 필요, 젠킨스 마스터-슬레이브 구조에서는 파라미터로 마스터-슬레이브 정의 가능
dir명령을 수행할 디렉토리 / 폴더 정의
stage파이프라인의 각 단계를 얘기하며, 이 단계에서 어떤 작업을 실행할지 선언하는 곳(즉, 작업의 본문)
gitGit 원격 저장소에서 프로젝트 Clone
shUnix 환경에서 실행할 명령어 실행. 윈도우에서는 bat
defGroovy 변수 혹은 함수 선언
profile
개발어린이

0개의 댓글