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