2

I am using GitLab CI/CD to build and push a docker image to my private GitLab registry.

I am able to successfully SSH into my server from the pipeline runner, but any commands passed into the SSH session doesn't run.

I am trying to pull the latest image from my GitLab container registry, run it, and exit the session to gracefully (successfully) pass the data to my pipeline.

The command I am running is:

ssh -t user@123.456.789 "docker pull registry.gitlab.com/user/project:latest & docker run project:latest"

The above command connects me to my server, and I see the typical welcome message, but the session hangs and no commands are ran.

I have tried using the heredoc format to pass in multiple commands at once, but I can't get a single command to work.

Any advice is appreciated.

Soumen Mukherjee
  • 2,953
  • 3
  • 22
  • 34
confusedandamused
  • 746
  • 2
  • 8
  • 28
  • & will background the process, && will chain the processes if process 1 exits with a successful return code. – masseyb Sep 22 '19 at 07:12

1 Answers1

2

For testing, you can try

ssh user@123.456.789 ls

To chain command, avoid using the '&', which would make the first command run in the background, while acting as command separator.

Try:

ssh user@123.456.789 "ls; pwd"

If this work, then try the two docker command, separated by ';'

Try with a docker run -td (that I mentioned here) in order to detach the docker process, without requiring a tty.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250