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
75 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 by Kalgi
• 40,460 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 in Jenkins by Mukul

closed Jul 5 by Vardhan 81 views
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,890 points
253 views
0 votes
2 answers
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
• 40,460 points
64 views