Karias Bolster
Karias Bolster

Reputation: 1035

Using docker as agent in jenkins pipeline yields to a docker command not found

Why is it that docker not found when i use docker as an agent in jenkins pipeline?

+ docker inspect -f . node:7-alpine
/var/jenkins_home/workspace/poobao-aws-services@tmp/durable- 
13f890b0/script.sh: 2: /var/jenkins_home/workspace/project- 
name@tmp/durable-13f890b0/script.sh: docker: not found

In Global Tools Configuration, I have docker as automatically install.

Upvotes: 0

Views: 1033

Answers (1)

0909EM
0909EM

Reputation: 5027

I have docker set to install automatically as follows, with a declarative pipeline as follows...

Docker Install

My jenkinsfile then has this initialization stage (amended from here)

stage('Install dependencies') {
  steps {
    script {
      def dockerTool = tool name: 'docker', type: 'org.jenkinsci.plugins.docker.commons.tools.DockerTool'
      withEnv(["DOCKER=${dockerTool}/bin"]) {
          //stages
          //here we can trigger: sh "sudo ${DOCKER}/docker ..."
      }
    }
  }
}

When built it then installs automatically...

enter image description here

Upvotes: 1

Related Questions