Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jenkinsfile - how to use scripted pipeline to launch a docker node

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.

like image 996
zanyman Avatar asked Jul 12 '18 20:07

zanyman


1 Answers

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"
        }
    }
}
like image 69
Chris Maes Avatar answered Sep 16 '22 15:09

Chris Maes