Jenkinsfile - how to pass build argument to docker

Viewed 18539

As per this link we can pass image name & dockerfile location to build an image in following way

docker.build("my-image:${env.BUILD_ID}", "-f ${dockerfile} ./dockerfiles")

I want to pass proxy settings to build command, Is there any way to pass it, similar to how we can pass in simple docker command.

docker build -t my-image --build-arg HTTP_PROXY=http://192.168.0.1:3128 ./dockerfiles
5 Answers

This works for me:

def image = docker.build("myregistry.io/firstkey/secondkey/image:2.2.0-$BUILD_NUMBER", "--build-arg http_proxy=http://www-proxy.mycompany.com:80 --build-arg https_proxy=http://www-proxy.mycompay.com:80 --network host -f Dockerfile .")
docker.build("my-image:${env.BUILD_ID}", "--build-arg HTTP_PROXY=http://192.168.0.1:3128", "-f ${dockerfile} ./dockerfiles")

All you need to add . in the second argument.

docker.build("my-image:${env.BUILD_ID}", "--build-arg HTTP_PROXY=http://192.168.0.1:3128 .")

You need to pass it like this, with giving space in between as a string

docker.build "my-image:${env.BUILD_ID} -f ${dockerfile} ./dockerfiles"

Related