接收带有空格和双引号的字符串时,如何在 Linux 上正确解析 Jenkins 运行 中的构建参数?
How to correctly parse build parameters in Jenkins running on Linux when receiving a string with spaces and double quotes?
我配置了一个参数化的 Jenkins Job 构建,它采用以下名为 "testcases" 的参数:
-t "Can Get Fake Name" -t "Can call Password"
这是一个必须通过命令行传递给机器人框架可执行文件的字符串。
Jenkins 在 Linux (Centos 7) 上 运行,这是我为实现目标而编写的构建脚本:
robot "${testcases}" myrobottest.robot
我找到了${testcases}
建议here,它部分解决了我的问题。
Jenkins上的结果命令如下:
+ robot '-t "Can Get Fake Name" -t "Can call Password"' myrobottest.robot
[ ERROR ] Suite 'myrobottest' contains no tests named ' "Can Get Fake Name" -t "Can call Password"'.
这里的问题是我不知道如何删除(或不生成)尾随的单引号。
在使用 ${testcases}
符号之前,我还尝试使用像 $testcases
这样的环境变量,但它会产生一些带有许多无用的单引号的东西。
有什么建议吗?
我希望生成的命令行是
robot -t "Can Get Fake Name" -t "Can call Password" myrobottest.robot
但实际输出是:
robot '-t "Can Get Fake Name" -t "Can call Password"' myrobottest.robot
编辑
我又做了一次尝试。
如果我如下更改脚本行:
eval echo robot ${testcases} docker-robot-framework.robot
我得到以下控制台输出。
+ eval echo robot '${testcases}' myrobottest.robot
++ echo robot -t '"Can' Get Fake 'Name"' myrobottest.robot
robot -t "Can Get Fake Name" myrobottest.robot
我想我已经接近解决方案了,因为我只需要执行这样的 eval
表达式(顺便说一句,这是正确的)。
尝试删除 ${testcases}
周围的 "
IFS=$'\n'
robot ${testcases} myrobottest.robot
我通过以下方式解决了问题:
/bin/sh -c "robot $testcases myrobottest.robot"
实际上,执行的结果命令行现在是正确的,并且可以工作:
/bin/sh -c 'robot -t "Can Get Fake Name" -t "Can call Password" myrobottest.robot'
我配置了一个参数化的 Jenkins Job 构建,它采用以下名为 "testcases" 的参数:
-t "Can Get Fake Name" -t "Can call Password"
这是一个必须通过命令行传递给机器人框架可执行文件的字符串。
Jenkins 在 Linux (Centos 7) 上 运行,这是我为实现目标而编写的构建脚本:
robot "${testcases}" myrobottest.robot
我找到了${testcases}
建议here,它部分解决了我的问题。
Jenkins上的结果命令如下:
+ robot '-t "Can Get Fake Name" -t "Can call Password"' myrobottest.robot
[ ERROR ] Suite 'myrobottest' contains no tests named ' "Can Get Fake Name" -t "Can call Password"'.
这里的问题是我不知道如何删除(或不生成)尾随的单引号。
在使用 ${testcases}
符号之前,我还尝试使用像 $testcases
这样的环境变量,但它会产生一些带有许多无用的单引号的东西。
有什么建议吗?
我希望生成的命令行是
robot -t "Can Get Fake Name" -t "Can call Password" myrobottest.robot
但实际输出是:
robot '-t "Can Get Fake Name" -t "Can call Password"' myrobottest.robot
编辑
我又做了一次尝试。 如果我如下更改脚本行:
eval echo robot ${testcases} docker-robot-framework.robot
我得到以下控制台输出。
+ eval echo robot '${testcases}' myrobottest.robot
++ echo robot -t '"Can' Get Fake 'Name"' myrobottest.robot
robot -t "Can Get Fake Name" myrobottest.robot
我想我已经接近解决方案了,因为我只需要执行这样的 eval
表达式(顺便说一句,这是正确的)。
尝试删除 ${testcases}
"
IFS=$'\n'
robot ${testcases} myrobottest.robot
我通过以下方式解决了问题:
/bin/sh -c "robot $testcases myrobottest.robot"
实际上,执行的结果命令行现在是正确的,并且可以工作:
/bin/sh -c 'robot -t "Can Get Fake Name" -t "Can call Password" myrobottest.robot'