我需要使用“&&”一步执行多个命令。所以我创建工厂如下:
f1 = factory.BuildFactory()
f1.addStep(shell.ShellCommand, command=["sh", "-c", "pwd", "&&", "cd", "/home/xxx/yyy", "&&", "pwd"])
但是在执行过程中发现buildbot是这样处理的,导致无法执行
sh -c pwd '&&' cd /home/xxx/yyy '&&' pwd
我期望的是
sh -c pwd && cd /home/xxx/yyy && pwd
有人可以帮我解决这个问题吗?谢谢。
最佳答案
由于您使用的是 /bin/sh
无论如何,只需用一个字符串调用它:
f1.addStep(shell.ShellCommand, command="pwd && cd /home/xxx/yyy && pwd")
正如文档所说:
The ShellCommand arguments are:
command
a list of strings (preferred) or single string (discouraged) which specifies the command to be run. A list of strings is preferred because it can be used directly as an argv array. Using a single string (with embedded spaces) requires the buildslave to pass the string to /bin/sh for interpretation, which raises all sorts of difficult questions about how to escape or interpret shell metacharacters.
不建议这样做,但无论如何您仍然需要 shell,如
&&
仅在 shell 内解释。调用 sh
只会是多余的。
关于shell - 如何在buildbot的shell命令行中添加 "&&"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25308364/