Program to execute Dockerfile using Jenkins declarative pipeline

0 votes
Program to execute Dockerfile using Jenkins declarative pipeline at a particular stage.

Precondition - a) Dockerfile name is different b) Dockerfile dir is different not in Jenkins workspace c)Both Jenkins and Docker are on same machine
Apr 12 in Jenkins by Nishant
• 160 points
19 views
Can you please provide more details
My objective is to pull the docker image from docker hub using dockerfile.I am looking to achieve this using Jenkins declarative pileline.

Q1.What is the code behind this?

Q2.My docker file name is "hellodocker.txt" so what is the code to execute this docker file

Q3.My docker file is in a different directory and not in not in Jenkins workspace /var/lib/jenkins/workspace hence what is the code to pickup the file from other directory

Q4.What is the code to put a tag/label to the docker image?
Are you trying to achieve all of this using the Jenkins pipeline?
yes I am trying to achieve via the jenkins pipeline (Declarative)

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Hey @Nishant, you can use something like this in your pipeline and in pull the docker image in your Dockerfile.

agent {
    // Equivalent to "docker build -f Dockerfile.build --build-arg version=1.0.2 ./build/
    dockerfile {
        filename 'Dockerfile.build'
        dir 'build'
        label 'my-defined-label'
        additionalBuildArgs  '--build-arg version=1.0.2'
          }
}

Basically, when you use agent as Dockerfile, it assumes that it has to execute the dockerfile. In the filename parameter specify the dockerfile name, in dir mention the directory, add a label to it using label.

answered Apr 15 by Kalgi
• 35,750 points

Related Questions In Jenkins

0 votes
1 answer

Error while talking to remote Oracle DB using Jenkins-CI

I installed Oracle XE to talk to ...READ MORE

answered May 1, 2018 in Jenkins by shubham
• 6,480 points
171 views
0 votes
2 answers
0 votes
1 answer

How to trigger a Jenkins pipeline A in another Jenkins pipeline B?

You can run the following code, its ...READ MORE

answered Jul 5, 2018 in Jenkins by Sophie may
• 9,050 points
760 views
0 votes
1 answer

How to rebuild an item on Jenkins pipeline

Yes you can, its pretty simple actually. Go ...READ MORE

answered Jul 10, 2018 in Jenkins by Kalgi
• 2,620 points
83 views
0 votes
1 answer
0 votes
1 answer
+1 vote
3 answers
0 votes
1 answer

Jenkins Pipeline using Openshift

Create a new service account in openshift ...READ MORE

answered Aug 8, 2018 in Jenkins by Kalgi
• 35,750 points
27 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.