코드로서의 파이프라인을 지원하는 기능
빌드, 테스트, 배포 등의 소프트웨어 개발 프로세스를 코드로 정의할 수 있게 한다.
pipeline {
...
}
any
라면 가용한 모든 에이전트에서 실행된다agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
stage('Test') {
steps {
echo 'Testing...'
}
}
stage('Deploy') {
steps {
echo 'Deploying...'
}
}
}
steps {
echo 'Hello, World!'
}
만약에 한 단계가 실패했다고 하면
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!";
}
}
}
}
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 | 설명 |
---|---|
node | Scripted 파이프라인을 실행하는 젠킨스 에이전트 최상단 선언 필요, 젠킨스 마스터-슬레이브 구조에서는 파라미터로 마스터-슬레이브 정의 가능 |
dir | 명령을 수행할 디렉토리 / 폴더 정의 |
stage | 파이프라인의 각 단계를 얘기하며, 이 단계에서 어떤 작업을 실행할지 선언하는 곳(즉, 작업의 본문) |
git | Git 원격 저장소에서 프로젝트 Clone |
sh | Unix 환경에서 실행할 명령어 실행. 윈도우에서는 bat |
def | Groovy 변수 혹은 함수 선언 |