
CI/CD 파이프라인은 소프트웨어를 자동으로 통합, 테스트, 배포하는 과정입니다. 이를 통해 개발 속도를 높이고 오류를 줄일 수 있습니다. Jenkins는 이런 작업을 자동으로 처리하는 도구이며, 특히 파이프라인 스크립트를 이용해 쉽게 설정할 수 있습니다.
Pipeline script (Webadmin)
일반적인 방식으로 Jenkins Pipeline을 생성해 Shell Script를 직접 생성하고 빌드
Git SCM
Git에 JenkinsFile을 작성하고, 빌드 시작 시 파이프라인 프로젝트에서 호출 실행
Blue Ocean
UI기반으로 시각적으로 파이프라인을 구성하면, JenkinsFile이 자동으로 생성되어 실행



pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
// 빌드 명령어 (예: sh 'mvn clean install')
}
}
stage('Test') {
steps {
echo 'Testing...'
// 테스트 명령어 (예: sh 'mvn test')
}
}
stage('Deploy') {
steps {
echo 'Deploying...'
// 배포 명령어 (예: sh 'deploy.sh')
}
}
}
}
pipeline {
agent any
environment {
MY_ENV_VAR = 'Hello, World!'
}
stages {
stage('Display Environment Variable') {
steps {
echo "The value of MY_ENV_VAR is: ${env.MY_ENV_VAR}"
}
}
}
}
pipeline {
agent any
stages {
stage('Build and Test') {
parallel {
stage('Build') {
steps {
echo 'Building...'
}
}
stage('Test') {
steps {
echo 'Testing...'
}
}
}
}
stage('Deploy') {
steps {
echo 'Deploying...'
}
}
}
}
pipeline {
agent any
triggers {
cron('H */4 * * 1-5')
}
stages {
stage('Example') {
steps {
echo 'Hello World'
}
}
}
}
pipeline {
agent any
stages {
stage('Approval') {
steps {
script {
input message: 'Proceed with deployment?', ok: 'Yes'
}
}
}
stage('Deploy') {
steps {
echo 'Deploying...'
}
}
}
}
@Library('my-shared-library') _
pipeline {
agent any
stages {
stage('Build') {
steps {
mySharedLibrary.build() // 공유 라이브러리의 빌드 메서드 호출
}
}
}
}
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
post {
success {
echo 'Build succeeded!'
}
failure {
echo 'Build failed!'
}
always {
echo 'This runs regardless of the build result.'
}
}
}
pipeline {
agent {
docker {
image 'maven:3.6.3-jdk-8'
args '-v /var/run/docker.sock:/var/run/docker.sock' // Docker 컨테이너 내에서 Docker를 사용하려면 이 설정이 필요
}
}
stages {
stage('Build') {
steps {
sh 'mvn clean install'
}
}
}
}
pipeline {
agent any
parameters {
string(name: 'VERSION', defaultValue: '1.0', description: 'Version to deploy')
}
stages {
stage('Deploy') {
steps {
echo "Deploying version: ${params.VERSION}"
// 배포 명령어 (예: sh "deploy.sh ${params.VERSION}")
}
}
}
}
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
stage('Test') {
steps {
echo 'Testing...'
}
}
stage('Deploy') {
when {
expression { params.DEPLOY == 'true' }
}
steps {
echo 'Deploying...'
}
}
}
}
pipeline {
agent any
stages {
stage('Build') {
steps {
script {
try {
echo 'Building...'
// 빌드 명령어 (예: sh 'mvn clean install')
} catch (Exception e) {
echo "Build failed: ${e.message}"
currentBuild.result = 'FAILURE'
}
}
}
}
stage('Notify') {
steps {
echo 'Notifying...'
// 알림 전송 명령어 (예: sh 'send-notification.sh')
}
}
}
}
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
stage('Archive') {
steps {
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
}
}
}
}