Jenkins job이나 이벤트들을 연속적으로 실행시키는 등의 일을 지원하는 기능
여러 방식으로 구현 가능
1) Jenkins Webadmin
: Jenkins Pipeline을 생성해 Shell Script를 직접 생성하고 빌드
2) Git SCM
: Git Repository에 JenkinsFile을 작성해 빌드
3) Blue Ocean
: Pipeline을 시각화하여 손쉽게 구성하고 빌드
2가지 타입의 문법
1) Scripted Pipeline
: Groovy로 빌드되기 때문에 pipeline을 생성하는데 보다 유연한 방법
2) Declarative Pipeline
: 고정된 방식이지만 간단하게 작성할 수 있는 방법
*1)과 2)는 호환되지 않음
pipeline {
agent any
stages {
stage('Example') {
steps {
echo 'Hello World'
}
}
}
post {
always {
echo 'I will always say Hello again!'
}
}
}
parameters
- any: 사용 가능한 agent
- none: global agent는 설정되지 않음, 대신 각 stage에 설정 필요
- label: 특정 label명으로 된 environment로 설정
- node: label과 유사
- docker: 특정 docker 이미지로 수행
- dockerfile: dockerfile 기반으로 수행
pipeline {
agent none
stages {
stage('Example Build') {
agent { docker 'maven:3-alpine' }
steps {
echo 'Hello, Maven'
sh 'mvn --version'
}
}
stage('Example Test') {
agent { docker 'openjdk:8-jre' }
steps {
echo 'Hello, JDK'
sh 'java -version'
}
}
}
}
pipeline {
agent any
environment {
CC = 'clang'
}
stages {
stage('Example') {
environment {
AN_ACCESS_KEY = credentials('my-prefined-secret-text')
}
steps {
sh 'printenv'
}
}
}
}
pipeline {
agent any
stages {
stage('Example') {
steps {
echo 'Building Container..'
script {
if (ENVIRONMENT_NAME == 'development') {
ENV_NAME = 'Development'
}
else if (ENVIRONMENT_NAME == 'release') {
ENV_NAME = 'Production'
}
}
echo 'Building Branch: ' + env.BRANCH_NAME
echo 'Build Number: ' + env.BUILD_NUMBER
echo 'Building Environment: ' + ENV_NAME
echo 'Running your service with environment ${ENV_NAME} now'
}
}
}
}
pipeline {
agent any
options {
timeout(time: 1, unit: 'HOURS')
}
stages {
stage('Example') {
steps {
echo 'Hello World'
}
}
}
}
pipeline {
agent any
parameters {
string(name: 'PERSON', defaultValue: 'Mr Jenkins', description: 'Who should I say hello to?')
text(name: 'BIOGRAPHY', defaultValue: '', description: 'Enter some information about the person')
booleanParam(name: 'TOGGLE', defaultValue: true, description: 'Toggle this value')
choice(name: 'CHOICE', choices: ['One', 'Two', 'Three'], description: 'Pick something')
password(name: 'PASSWORD', defaultValue: 'SECRET', description: 'Enter a password')
}
stages {
stage('Example') {
steps {
echo "Hello ${params.PERSON}"
echo "Biography: ${params.BIOGRAPHY}"
echo "Toggle: ${params.TOGGLE}"
echo "Choice: ${params.CHOICE}"
echo "Password: ${params.PASSWORD}"
}
}
}
}