Search code examples
bashyamlbitbucket-pipelines

Yaml based multiline bash script not terminating


For a bitbucket pipeline I'm using the following after-script:

          after-script:
            - |-
              ssh -tt -p 222 user@example.com "/bin/bash" << EOF
              cd public_html/staging && npm i && pm2 delete my-app || : && VITE_BASE_URL=$VITE_BASE_URL pm2 -f start build/index.js --update-env --name my-app
              EOF

Here I do the following:

  1. connect to the server and use bash
  2. start a multiline command
  3. move to the copied code
  4. install dependencies
  5. delete app if exists, then start it
  6. end the script

Now for step 6 it doesn't work as expected. The process doesn't stop and the pipeline keeps running.

I assume I made some kind of syntax mistake, but I can't figure out what I did wrong.

best regards

EDIT 1: When removing the flag -tt I get the following errors:

/bin/bash: line 1: npm: command not found
/bin/bash: line 1: pm2: command not found

I don't think there is anything I can do about that, since I am not able to change the servers settings

removing the last EOT in the code, causes this error to pop up, while the process doesn't finish:

schwad@dedivirt2847:~/public_html/staging$ printf "\n"

EDIT 2:

replacing |- with | doesn't change anything. The process still doesn't terminate.

Removing the last EOF has the same effect


Solution

  • I could make it work by calling exit 0 manually:

             after-script:
                - |-
                  ssh -tt -p 222 user@example.com "/bin/bash" << EOF
                  cd public_html/staging && npm i && pm2 delete my-app || : && VITE_BASE_URL=$VITE_BASE_URL pm2 -f start build/index.js --update-env --name my-app
                - exit 0