Last active
June 20, 2021 16:39
-
-
Save toshke/905927a58e62e0267fdc7e3e4d0da02f to your computer and use it in GitHub Desktop.
Declarative jenkins pipeline example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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