微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 Cygwin 中回显 Jenkins 工作区

如何解决如何在 Cygwin 中回显 Jenkins 工作区

我正在尝试从 jenkins 管道构建作业,我的管道正在调用 Windows 服务器上的一个 shell 脚本,而该脚本位于 cygwin 终端中,问题是如何在 cygwin 的 shell 脚本中使用 Jenkins 工作区,尝试以下命令不起作用,有人可以请教。谢谢。

In jenkins Pipeline:
    
     sh "/home/test.sh $WORKSPACE"
In Cygwin:
#!/cygdrive/d/cygwin64/bin/bash --login

WORKSPACE=$1
echo "$WORKSPACE"

Out put from above command is 
D:Jenkinsworkspacey_test123_feature_test

but actual workspace is(multibranch pipeline) 
Running on win01 in D:\Jenkins\workspace\y_test123_feature_test

不确定 cygwin 是否会采用不同的命令来检索工作区,因为您可以看到上面的输出在单词之间不包含斜杠。

解决方法

可以使用管道内的环境变量访问工作区。

In jenkins Pipeline:
// Get workspace
// This will give you the workspace of the agent that is available in the current stage
def Workspace=env.WORKSPACE
// Convert path with \\ for cygwin
Workspace.replace("\\","\\\\");
println(Workspace)
sh "/home/test.sh ${Workspace}"

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。