what is the syntax for scripted pipeline(i.e. node{} block as the top-level) to use a docker container(from a dockerhub image or dockerfile for example)?
I know how to use declaritive pipeline to do this, just specify a agent block and put docker inside. I want to know how to use scripted pipeline syntax to do so.
You can do this like:
node('docker-host') {
checkout scm
docker.withRegistry('registry-url', 'credentials-id') {
def dockerfile = "path/to/Dockerfile"
def buildImage = docker.build("my-image-${env.GIT_COMMIT}", "-f $dockerfile .")
buildImage.inside('-v /tmp:/tmp') {
echo "inside docker"
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With