docker exec在Jenkins

时间:2017-02-23 02:06:05

标签: jenkins docker jenkins-pipeline

我使用Jenkins + Pipeline + DockerPlugin来构建和运行带有远程主机的docker容器,当执行命令时如下:
docker.withServer("tcp://192.168.1.122:2375",'') {
    def wait_results = sh(script: "docker exec -t development-taxpayer-server-131-1 echo aaa", returnStdout: true)
    print wait_results
}
  

wait_results:无需打印

预期结果是在Jenkins控制台日志中打印'aaa'。

远程泊坞广告版本是:

Client:
 Version:      1.12.5
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   7392c3b
 Built:        Fri Dec 16 02:23:59 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.12.5
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   7392c3b
 Built:        Fri Dec 16 02:23:59 2016
 OS/Arch:      linux/amd64

1 个答案:

答案 0 :(得分:0)

尝试改为

def wait_results = sh(script: "docker ps -a", returnStdout: true)

这样你至少可以检查:

  • docker正在运作
  • 容器development-taxpayer-server-131-1正在运行

然后,考虑docker exec syntax,请尝试-it

def wait_results = sh(script: "docker exec -it development-taxpayer-server-131-1 echo aaa", returnStdout: true)

注意:“How to run a command on an already existing docker container?”显示相同的回显没有任何选项:

docker exec development-taxpayer-server-131-1 echo aaa