Skip to content

Instantly share code, notes, and snippets.

@toshke
Last active June 20, 2021 16:39
Show Gist options
  • Save toshke/905927a58e62e0267fdc7e3e4d0da02f to your computer and use it in GitHub Desktop.
Save toshke/905927a58e62e0267fdc7e3e4d0da02f to your computer and use it in GitHub Desktop.
Declarative jenkins pipeline example
pipeline {
//run by default on docker-in-docker slave
agent {
label 'docker'
}
stages {
//demo of running builds within custom container
stage('PrintNodeVersion') {
//run this stage within docker container created out of
//node:8 image
agent {
docker {
image 'node:8-alpine'
}
}
//print out node version
steps {
sh 'node -v'
}
}
//demo for building and pushing container
stage('BuildCiinaboxSlaveImage'){
agent {
label 'docker-dood'
}
steps {
//script is denoting standard Jenkins pipeline code
script {
git url: 'https://github.com/base2Services/ciinabox-containers.git'
}
script {
dir('jenkins/2') {
docker.build('base2/ciinabox-jenkins')
}
}
}
}
//demo for using shared pipeline library
stage('ShellOutFromSharedLib'){
agent {
label 'docker-dood'
}
//no need to specify agent as it is already specified
//on top level pipeline
steps {
script {
//load shared pipelines library
@Library('github.com/base2Services/ciinabox-pipelines@master')
//use shellOut helper method from pipeline
//library to list docker images on agent
def dockerVersion = shellOut('docker --version')
echo "Docker version on agent:\n\n${dockerVersion}"
sh "docker info"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment