Executing remote shell script during CI/CD fails without error message

Hi there,

if I missed a rule posting this here, sorry, I tried to find the right place and hope I am correct.

I am trying to deploy a jar file on a remote server with the CI/CD pipeline. Uploading the file with scp works totally fine. No I want to run a remote shell script, killing the old process and starting the new one.

My deploy stage looks as follows:

  stage: deploy
  image: ubuntu:latest
  environment: Staging
    - apt-get update -qq && apt-get install -y -qq sshpass
    - sshpass -V
    - export SSHPASS=$USER_PASS
    - sshpass -e ssh devopslab@xxx.com '/home/devopslab/xxx/stop.sh'
    - sshpass -e scp -o stricthostkeychecking=no -r ./target/*.jar devopslab@xxx.com:/home/devopslab/xxx
    - sshpass -e ssh devopslab@xxx.com 'home/devopslab/xxx/start.sh'

The stop.sh script e.g. looks as follows:

nohup kill -9 `cat /home/devopslab/zuul/zuul.pid` >/dev/null 2>&1 &

Everything works fine, when calling it locally. But as soon, as I call the script via gitlab ci/cd it fails with the following message:

Using "assword" as the default password prompt indicator.
$ sshpass -e ssh devopslab@xxx.com '/home/devopslab/xxx/stop.sh'
ERROR: Job failed: exit code 1

Anyone got an idea?

Thanks upfront!

Thanks to tabakhase, I was able to solve the issue. Wrapping the ssh commands with script, solved the issue.

  • script -qc “sshpass -e ssh -l devopslab gitlab.xxx.com /home/devopslab/xxx/stop.sh” /dev/null
1 Like

That solved my problem!