我为jenkins执行了以下shell脚本:
#!/bin/bash
ssh user@perftest03 -f '~/setup_environment.sh load/LoadConfig.xml'
取决于一天中的时间或Jenkins想要的东西,或者我所知道的老神,脚本执行部分或更多脚本,但总是在它完成之前退出。这是两个不同的日志,具有相同的执行,相同的脚本,并且没有任何更改:
Started by user Andreas Joelsson
[EnvInject] - Loading node environment variables.
Building remotely on linuxdev01 in workspace /home/byggarebob/workspace/Project-Load
[Project-Load] $ /bin/bash /tmp/hudson1526996494849043502.sh
MG_DIRECTORY ==> /home/user/user
MG_SYMLINK ==> /home/user/user/RunnerConfig.xml
MGC_DIRECTORY ==> /home/user/user-config
MGC_REPOSITORY ==> git@git.company.se:test/user-config.git
MGC_BRANCH ==> develop
MGC_FILE ==> /home/user/user-config/load/LoadConfig.xml
Changing directory to "/home/user/user-config".
cd /home/user/user-config
git show-ref --verify --quiet refs/heads/develop
Checking if we are in branch develop.
git branch | grep --quiet '* develop'
Finished: SUCCESS
和
Started by user Andreas Joelsson
[EnvInject] - Loading node environment variables.
Building remotely on linuxdev01 in workspace /home/byggarebob/workspace/Project-Load
[Project-Load] $ /bin/bash /tmp/hudson7204317023088063558.sh
MG_DIRECTORY ==> /home/user/user
MG_SYMLINK ==> /home/user/user/RunnerConfig.xml
MGC_DIRECTORY ==> /home/user/user-config
MGC_REPOSITORY ==> git@git.company.se:test/user-config.git
MGC_BRANCH ==> develop
MGC_FILE ==> /home/user/user-config/load/LoadConfig.xml
Changing directory to "/home/user/user-config".
cd /home/user/user-config
git show-ref --verify --quiet refs/heads/develop
Finished: SUCCESS
所以我设法运行 git show-ref --verify --quiet refs / heads / develop 并继续,而另一个停在它,我也在更改目录和事件处停止打印输出取决于服务器的情绪,我已经让它工作一次,但它显然是一些我无法找到的随机元素。
以下是已停止执行的shell脚本的部分(它会持续更长时间,但我不想泛滥页面)
if [ ! -d "$MGC_DIRECTORY" ]; then
echo "Unable to clone $MGC_REPOSITORY, cannot continue"
exit 1
else
echo "Changing directory to \"$MGC_DIRECTORY\"."
if [ -n $VERBOSE ]; then
echo "cd $MGC_DIRECTORY"
fi
cd $MGC_DIRECTORY
fi
if [ -n $VERBOSE ]; then
echo "git show-ref --verify --quiet refs/heads/$MGC_BRANCH"
fi
git show-ref --verify --quiet refs/heads/$MGC_BRANCH
if [ $? != 0 ]; then
echo "No branch found in $MGC_DIRECTORY called $MGC_BRANCH."
exit 1
fi
echo "Checking if we are in branch $MGC_BRANCH."
if [ -n $VERBOSE ]; then
echo "git branch | grep --quiet '* $MGC_BRANCH'"
fi
git status | grep --quiet '* $MGC_BRANCH'
我有一个理论认为第一个成功的shell命令(返回0)会中断执行,但是一些测试用例在我们设法更改目录时打破了这个理论。
我已检查https://wiki.jenkins-ci.org/display/JENKINS/SSH+Agent+Plugin插件,但似乎已损坏/无法正确设置。
答案 0 :(得分:0)
#!/bin/bash
ssh user@perftest03 '~/setup_environment.sh load/LoadConfig.xml'
通过谷歌搜索解决了它,由于某种原因,我认为我需要-f标志才能工作。正在朝着错误的方向寻找答案。