I am trying to execute a build script from Jenkins that builds and deploys a website (the script is multipurpose, but it is executed by running bash ./scripts/deploy.sh -ssh
):
#!/usr/bin/env bash
cd ..
rm -rf _site/
if [ "$1" = "-ssh" ]; then
git clone git@github.com:RIT-EVT/RIT-EVT.github.io.git --branch master --depth 1 _site
else
git clone https://github.com/RIT-EVT/RIT-EVT.github.io.git --branch master --depth 1 _site
fi
LIVE_VERSION_BUILD=`cat _site/version`
LIVE_VERSION=${LIVE_VERSION_BUILD%.*}
LIVE_BUILD=${LIVE_VERSION_BUILD##*.}
PACKAGE_VERSION=`sed -nE 's/^\s*"version": "(.*?)",$/\1/p' package.json`
if [[ "$LIVE_VERSION" == "$PACKAGE_VERSION" ]]; then
((LIVE_BUILD++))
else
LIVE_VERSION=${PACKAGE_VERSION}
LIVE_BUILD=0
fi
rm -rf _site/*
jekyll build
echo "$LIVE_VERSION.$LIVE_BUILD" > _site/version
cd _site/
git add -A
git commit -m "v$LIVE_VERSION.$LIVE_BUILD $(date)"
git push
cd ..
The issue I have is bash does not execute the script as expected (tested against running the script on my computer with the same version of bash). I keep receiving the following output, and then the script just fails (I had to work around the above issue by using HTTPS and entering the username and password in the git repo url: https://username:password@github.com/...):
...
Cloning into '_site'...
++ cat _site/version
+ LIVE_VERSION_BUILD=0.0.9.0
+ LIVE_VERSION=0.0.9
+ LIVE_BUILD=0
++ sed -nE 's/^\s*"version": "(.*?)",$/\1/p' ./package.json
+ PACKAGE_VERSION=0.0.9
+ [[ 0.0.9 == \0\.\0\.\9 ]]
+ (( LIVE_BUILD++ ))
Build step 'Execute shell' marked build as failure
Finished: FAILURE