【发布时间】:2017-03-07 23:25:19
【问题描述】:
我正在尝试从 Jenkins 执行构建和部署网站的构建脚本(该脚本是多用途的,但通过运行 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 ..
我遇到的问题是 bash 没有按预期执行脚本(针对在我的计算机上使用相同版本的 bash 运行脚本进行了测试)。我不断收到以下输出,然后脚本就失败了(我必须通过使用 HTTPS 并在 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
【问题讨论】: