0

I am trying to build Docker image by using Jenkins pipeline script. When I am running the following code,

docker build -f Dockerfile -t spacestudykubernetes /var/lib/jenkins/workspace/cicd/pipeline

I added this command in inside Jenkins pipeline job shell script. There "cd" command will not work. Change directory not working in shell script. Because of that without changing directly, I gave the command with full path. According to your command it will work (after putting change directory) . I am trying to execute from cicd folder, not from pipeline folder. Dockerfile is resides in pipeline folder.

My Jenkins pipeline script

pipeline 
{
    agent any
    stages 
        {
            stage ('imagebuild')
                {
                    steps
                        {

sh 'docker build -f Dockerfile -t spacestudykubernetes /var/lib/jenkins/workspace/cicd/pipeline'

                        }
                }
        }
}

Error

I am getting the error like the following,

unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /var/lib/jenkins/workspace/cicd/Dockerfile: no such file or directory

I am not running from direct folder where Dockerfile is resides. My Dockerfile is resides in pipeline folder. That is my code checked out from SVN. And I am trying to run this command from cicd folder. And I gave the full path with -f argument.

1 Answer 1

3

You miss context directory at the end of command line. Usually it is simply .. This directory will serve as root for all paths in Dockerfile whenever you use ADD/COPY and also as a build context - meaning its content will be zipped and passed to docker daemon when build is executed.

cd /var/lib/jenkins/workspace/cicd/pipeline
docker build -f Dockerfile -t spacestudykubernetes .
Sign up to request clarification or add additional context in comments.

7 Comments

Actually I added this command in inside jenkins pipeline job shell script. There "cd" command will not work. Change directory not working in shell script. Because of that without changing directlry , I gave the command with full path. According to your command it will work (after putting change directory) . I am trying to execute from cicd folder. not from pipeline folder. Dockerfile is resides in pipeline folder. I hope that you understood my problem. And Thank you for your response sir.
Not a problem, man, i've just put cd for convenience. You can put your full path instead of . at the end and enjoy
I changed like this - "docker build -f Dockerfile -t spacestudykubernetes /var/lib/jenkins/workspace/cicd/pipeline". But still I am getting error "unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /var/lib/jenkins/workspace/cicd/Dockerfile: no such file or directory"
Because path to Dockerfile itself is evaluated from your cwd, not from context. User docker build -f /var/lib/jenkins/workspace/cicd/pipeline/Dockerfile -t spacestudykubernetes /var/lib/jenkins/workspace/cicd/pipeline
BTW this allows the Dockerfile to be located outside build context
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.