1

I use Jenkins + Pipeline + DockerPlugin to build and run docker container with remote host, when execute command with the follow:

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 : nothing to print

the expect result is print 'aaa' in Jenkins console log.

the remote docker version is:

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
herryliq
  • 11
  • 1
  • 3

1 Answers1

1

Try instead

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

That way you can at least check that:

  • docker is working
  • the container development-taxpayer-server-131-1 is running

Then, considering the docker exec syntax, try -it:

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

Note: "How to run a command on an already existing docker container?" shows the same echo done without any option:

docker exec development-taxpayer-server-131-1 echo aaa
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • thanks, with your code it work well, this problem only when use "docker exec -t" – herryliq Feb 23 '17 at 05:30
  • @herryliq the goal was to know if you see the container in a running state – VonC Feb 23 '17 at 05:31
  • @herryliq I have edited the answer, using the proper syntax for `docker exec` – VonC Feb 23 '17 at 05:33
  • if use docker exec -it, jenkins will retun some error and exit the job. [docker-temp] Running shell script + docker exec -it production-taxpayer-server-129-1 echo aaa cannot enable tty mode on non tty input – herryliq Feb 23 '17 at 07:49
  • @herryliq OK, and without any option? Without -t -i? – VonC Feb 23 '17 at 07:50
  • yes, it will all same result. but when I use 'docker -h tcp://x.x.x.x:2375 exec development-taxpayer-server-131-1 echo aaa' with terminal, it work well. I think it will some bug in Jenkins docker plugin. – herryliq Feb 23 '17 at 07:56
  • @herryliq that is possible. The closest bug I see is https://issues.jenkins-ci.org/browse/JENKINS-41474 – VonC Feb 23 '17 at 11:41