在Jenkins中执行远程脚本(Execute remote script in Jenkins)

编程入门 行业动态 更新时间:2024-10-27 16:35:46
在Jenkins中执行远程脚本(Execute remote script in Jenkins)

我为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插件,但它似乎已被破坏/无法正确设置。

I have the following shell script execution for jenkins:

#!/bin/bash ssh user@perftest03 -f '~/setup_environment.sh load/LoadConfig.xml'

Depending on time of day or what Jenkins want, or the old gods for all I know the script executes part or more of the script, but always exits before it finishes. Here is 2 different logs with the same execution, same script and no changes to anything:

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

and

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

So one manages to run git show-ref --verify --quiet refs/heads/develop and continue, while the other stops at it, I also have stops at the change directory and event printout depending on the mood of the server, I have had it working once but it's clearly some random element which I cannot find.

Here is the parts of the shell script that is stopped executed (it goes on for longer but I don't want to flood the page)

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'

I have a theory that the first successful shell command (return 0) breaks the execution, but some of the test cases breaks this theory as we manage to change directory for example.

I have checked the https://wiki.jenkins-ci.org/display/JENKINS/SSH+Agent+Plugin plugin but it seems to be broken / not able to set it up correctly.

最满意答案

#!/bin/bash ssh user@perftest03 '~/setup_environment.sh load/LoadConfig.xml'

解决了它,由于某种原因谷歌搜索之后我认为我需要-f标志才能工作。 正在寻找错误的方向寻找答案。

#!/bin/bash ssh user@perftest03 '~/setup_environment.sh load/LoadConfig.xml'

Solved it, for some reason after googling I thought I needed the -f flag to work. Was looking in the wrong direction for the answer.

更多推荐

本文发布于:2023-07-16 10:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1126898.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   Jenkins   Execute   script   remote

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!