Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkinsfile - how to pass build argument to docker

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
like image 597
Dhananjay Avatar asked Jan 04 '19 11:01

Dhananjay


People also ask

Can you pass arguments to Dockerfile?

Here is the Dockerfile using both ARG and ENV together to take the PORT as the build argument. Here is the app running on the port 3090. In this way, we can pass as many arguments as possible to pass as environment variables while building the image.

How do I create a docker image in Jenkinsfile?

Click Manage Jenkins, then click Manage Credentials. Click global, then Add Credentials to add a new credential with a Global Scope. Add your Dockerhub username and password. The ID is used in the Jenkinsfile and stores the credentials.


2 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 .")
like image 147
Drew Avatar answered Oct 13 '22 13:10

Drew


docker.build("my-image:${env.BUILD_ID}", "--build-arg HTTP_PROXY=http://192.168.0.1:3128", "-f ${dockerfile} ./dockerfiles")
like image 21
yong Avatar answered Oct 13 '22 13:10

yong