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, 2019 in Jenkins by Nishant
• 160 points
2,445 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.

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, 2019 by Kalgi
• 52,350 points

Related Questions In Jenkins

+1 vote
1 answer
0 votes
0 answers

Developing Continuous Delivery Pipeline using Git, Jenkins, Maven & Tomcat - join link. Registered today but not geeting link to joinin

Developing Continuous Delivery Pipeline using Git, Jenkins, ...READ MORE

Jul 4, 2019 in Jenkins by Mukul

closed Jul 5, 2019 by Vardhan 1,144 views
0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer
+2 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
• 52,350 points
1,028 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP