-1

I am trying to SSH into my Compute Engine instance using CircleCI with a command that looks like this in config.yml:

gcloud --quiet compute ssh [INSTANCE_NAME] --zone northamerica-northeast1-a --project [PROJECT_NAME] cd /var/www/dev

I can successfully authenticate and see the command prompt in CircleCI logs. However, the commands after SSH are not being carried out. What am I doing wrong here?

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Sep 12 15:53:55 2018 from 18.212.180.159

[USER_NAME]:~$

I expect to have cd command run after successful authentication.

Jorjani
  • 133
  • 3
  • 12

1 Answers1

2

Using SSH, it seems you cannot change directory by just passing the command, and this is an SSH limitation per this Serverfault post. Generally, you can run an executable file using SSH by using -c flag, and similarly using --command with gcloud like this example.

gcloud compute ssh --zone=us-east1-c test --command="nohup ping -i 5 google.com > foo.out 2> foo.err < /dev/null &"

However, from the above serverfault post it seems that changing directory can be acheived by using -t flag, in addition to executing several commands in one statement. Luckily gcloud can also make use of such flags by adding --ssh-flag. Here is an example that changes directory and outputs the system path.

gcloud compute ssh --zone=us-central1-c  instance-2 --ssh-flag="-t" --command="cd /bin; pwd"
/bin
Connection to xx.xx.xx.xx closed.

Note that SSH exited (connection closed) once the last command pwd was executed. To stay logged in and as suggested in the post use bash --login

I am not sure in circleCI how commands are run, but in general to run a command in linux you can specify the full path directly, rather than changing directory. For example, /some/directory/executablefile will run the executablefile.

Fady
  • 206
  • 1
  • 5