In jenkins in the pipeline, it is jenkinsfile file, if you want to call docker to build the image, complete the following tasks!
Add docker in tools {} is a failure, which I find a lot of information, and finally the environment variable env need to solve the problem.
- We need to add a global variable items, such as name docker, the path / usr / local
- Jenkinsfile add a file, used to run the command docker
pipeline {
agent any
tools{
gradle "gradle"
}
stages {
stage('init') {
steps {
script{
def dockerPath = tool 'docker' //全局配置里的docker
env.PATH = "${dockerPath}/bin:${env.PATH}" //添加了系统环境变量上
}
}
}
stage('Build') {
steps {
script{
sh "docker --version"
}
}
}
}
}
Note: We need to add the path to the docker env environment variable before you can use docker command, I tried this many times.