https://www.jenkins.io/doc/pipeline/tour/getting-started/
code-deployment and review-automated-continuous-tool-plugin
pipeline-build-process
Sample
Declarative
pipeline {
agent any // Execute pipleine or any of its stages
stages {
stage('Build') { // Define Build stage
steps {
// Performs steps IN 'Build' stage
}
}
stage('Test') {
steps {
// Performs steps IN 'Test' stage
}
}
stage('Deploy') {
steps {
// Performs steps IN 'Deploy' stage
}
}
}
}
Scripted
node { // Execute pipleine or any of its stages
stage('Build') {
// Performs steps IN 'Build' stage
}
stage('Test') {
// Performs steps IN 'Test' stage
}
stage('Deploy') {
// Performs steps IN 'Deploy' stage
}
}
Declartive Sample
Jenkinsfile (Declarative Pipeline)
pipeline { // pipeline - Contain all content and instructions for executing pipeline
agent any // agent - Instructs Jenkins to allocate executor and workspace for pipeline
options {
skipStagesAfterUnstable()
}
stages { // stages - describes stages of this Pipeline.
stage('Build') {
steps { // Steps to be run in the stage
sh 'make' // Executes shell command
}
}
stage('Test'){
steps {
sh 'make check'
junit 'reports/**/*.xml' // Make test reports
}
}
stage('Deploy') {
steps {
sh 'make publish'
}
}
}
}
DockerBuild
agent {
// Equivalent to "docker build -f Dockerfile.build --build-arg version=1.0.2 ./build/
dockerfile {
filename 'Dockerfile.build'
dir 'build'
label 'my-defined-label'
additionalBuildArgs '--build-arg version=1.0.2'
args '-v /tmp:/tmp'
}
}
Kubernetes Build
https://github.com/jenkinsci/kubernetes-plugin/blob/master/examples/kaniko.groovy
pipeline {
agent any
stages {
stage('Test') {
steps {
sh 'echo "Fail!"; exit 1'
}
}
}
post {
always {
echo 'This will always run'
}
success {
echo 'This will run only if successful'
}
failure {
echo 'This will run only if failed'
}
unstable {
echo 'This will run only if the run was marked as unstable'
}
changed {
echo 'This will run only if the state of the Pipeline has changed'
echo 'For example, if the Pipeline was previously failing but is now successful'
}
}
}