Jenkinsfile - how to pass build argument to docker

14,634

Solution 1

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 .")

Solution 2

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

Solution 3

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 .")

Share:
14,634
Dhananjay
Author by

Dhananjay

Success is just that one extra debug away

Updated on June 09, 2022

Comments

  • Dhananjay
    Dhananjay almost 2 years

    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