I have a small shell script for deployment which I use in my bitbucket pipeline.
I successfully tested that bitbucket pipeline executes the script on my server with this step (I tried it by writing a one-line script which just inserts a file on the server -> it was created correctly after the pipe ran):
- step:
name: Deploy dev
trigger: manual
script:
- cat ./deploy.sh | ssh -T user@[myIp]
When I execute my deploy-script directly on the server after logging in via ssh it works great. But when the BitBucket Pipeline executes it, the last four commands are skipped for some reason.
This is the deploy.sh file :
#!/bin/bash
env="dev"
if [ $# -gt 0 ]; then
env=$1
fi
basePath="/path/to/my/project/${env}"
echo "---------------------------------------- | DEPLOYING TO ${env}"
cd ${basePath}
git stash
git pull
echo "---------------------------------------- | BUILD ANGULAR"
cd ${basePath}/Web/project
ng build
echo "---------------------------------------- | BUILD API"
cd ${basePath}/API
./gradlew build
echo "---------------------------------------- | KILL API"
sh ${basePath}/killAllServers.sh
mv ${basePath}/killAllServers.sh ${basePath}/log/archive/`date +%Y-%m-%d-%H:%M:%S`-killed.log
echo "---------------------------------------- | CLEAR LOGS"
mv ${basePath}/log/java-spring.log ${basePath}/log/archive/`date +%Y-%m-%d-%H:%M:%S`-spring.log
echo "---------------------------------------- | STARTING API"
java -jar ${basePath}/path/to/my/build.jar --spring.profiles.active=dev >> ${basePath}/log/java-spring.log & echo "kill $! #started on `date +%Y-%m-%d-%H:%M:%S`" >> ${basePath}/killAllServers.sh
Now when I execute it on my server I get the following output (I emitted some outputs from angular and gradle to make it easier readable):
user@[myIp]:/path/to/my/project$ sh deploy.sh
---------------------------------------- | DEPLOYING TO dev
Saved working directory and index state ... /**Git output**/
---------------------------------------- | BUILD ANGULAR
Your global Angular CLI version /**Angular Output**/
---------------------------------------- | BUILD API
BUILD SUCCESSFUL in 6s
3 actionable tasks: 3 up-to-date
---------------------------------------- | KILL API
---------------------------------------- | CLEAR LOGS
---------------------------------------- | STARTING API
When I execute it via the BitBucket Pipeline, this is the output that I get:
+ cat ./deploy.sh | ssh -T user@[myIp]
Welcome to Ubuntu /** Ubuntu Output**/
---------------------------------------- | DEPLOYING TO dev
Saved working directory and index state /** Git output**/
---------------------------------------- | BUILD ANGULAR
Your global Angular CLI version /** Angular Output**/
---------------------------------------- | BUILD API
> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :bootJar UP-TO-DATE
> Task :jar SKIPPED
> Task :assemble UP-TO-DATE
> Task :compileTestJava NO-SOURCE
> Task :processTestResources NO-SOURCE
> Task :testClasses UP-TO-DATE
> Task :test NO-SOURCE
> Task :check UP-TO-DATE
> Task :build UP-TO-DATE
BUILD SUCCESSFUL in 5s
3 actionable tasks: 3 up-to-date
I have no idea why the script doesn't execute the rest of the commands as well when executing via the pipeline.