【问题标题】:jenkins running scripts on windows slavejenkins 在 windows slave 上运行脚本
【发布时间】:2016-07-20 07:49:43
【问题描述】:

尝试从 jenkins 定义中提取所有各种构建脚本并将它们存储到源存储库中的一个或多个脚本中。

有些脚本是 shell 脚本,有些是批处理文件。一个 shell 脚本通过运行 c:\program files\git\git-bash.exe 并执行一些 git 命令来启动它(不,我没有使用插件 - 不是我的 jenkins 服务器,而且我得到了最严格、最小的访问做这项工作,所以我要从一个脚本文件运行 git 命令)。还完成了一些其他工作来设置变量、配置构建文件等。

我遇到的问题是尝试从该 shell 脚本运行批处理文件。

在 jenkins 中,我有一个 shell 脚本来启动进程(三个参数作为参数传递):

#!c:\Program Files\Git\git-bash.exe
/f/git/project/builds/step1.sh $MASTER_BRANCH $BUILD_TYPE $TAG_CLIENT

step1.sh 脚本一直运行到

# Override Jenkins value
WORKSPACE=/f/git/project
WIN_WORKSPACE=`cygpath -w $WORKSPACE | sed 's/\\\\/\\\\\\\\/g'`
echo "WIN_WORKSPACE: $WIN_WORKSPACE"
...
echo "Building!"
echo cmd.exe /c call builds\\step2.bat $WIN_WORKSPACE
cmd.exe /c call builds\\step2.bat $WIN_WORKSPACE
echo "done building"

发生的情况是,cmd.exe(带有或不带有“call”关键字)只是弹出到命令提示符并坐在那里,直到我键入“exit”:

Building!
cmd.exe /c call builds\step2.bat F:\\git\\project
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

F:\git\project>exit  <--- I have to type that.
exit
done building

是否可以从 git-bash shell 运行批处理文件?有更好的方法吗?我正在尝试转换为批处理文件,但语法(例如捕获命令输出和存储到变量)使用 shell 脚本更好。我还需要在构建过程的后期运行至少几个 shell(预期)脚本,以便与另一台服务器通信以完成构建的另一部分。

【问题讨论】:

    标签: bash shell batch-file jenkins


    【解决方案1】:

    希望这个痛苦简单的解决方案能奏效;将/c 替换为//c,所以:

    cmd.exe //c call builds\\step2.bat $WIN_WORKSPACE
    

    这是因为 git-bash 导致 posix 路径失败,即使您只打算通过内部命令传递它,所以它必须被转义。

    【讨论】:

    • 好的...做到了。为什么?
    • Git 在 windows 下不流畅,Cygwin 更适合 bash 和 cmd 交叉,所以 windows posix 路径无法通过。 herehereand maybe here
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-22
    • 2015-01-29
    • 1970-01-01
    • 1970-01-01
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多