0
votes

I am using Jenkins version 2.121.1 with Pipeline On MacOS-HighSierra.

I've a shell script called build_docker_image.sh that builds a docker image using the following command:

docker build -t test_api:1 -f test-dockerfile

test-dockerfile is a Dockerfile and has instructions to build an image.

From CLI the whole set up works! However, when I run it from Jenkins server Pipeline context, it is failing at the above line with an error: docker: command not found

The step that triggers from Jenkins server is simple. Call the script:

stage ('Build-Docker-Image') {
    steps {
        sh '/path/to/build-docker_image.sh'
    }
 }

In Jenkinsfile, I made sure the $PATH is including the path to Docker.

1
> I made sure the $PATH is including the path to Docker. < How did you do this? Env variables are not kept between steps. So try to set it inside your shell script. - StephenKing
@StephenKing Thanks for bringing my attention to the $PATH. I am using Declarative Pipeline. So, I do not need to handle environment variables in each step or inside shell script once I set it in environment directive it uses that. - user2995358
Thanks for letting me know. As you omitted the code, this was for me the most obvious thing... - StephenKing

1 Answers

0
votes

The issue was that I was appending the actual docker application like this /Applications/Docker.app/Contents/Resources/bin/docker, instead of the directory /Applications/Docker.app/Contents/Resources/bin