Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add "&&" in a shell command line in buildbot?

I need to use "&&" to execute multiple commands in one step. So I create factory as below:

f1 = factory.BuildFactory()
f1.addStep(shell.ShellCommand, command=["sh", "-c", "pwd", "&&", "cd", "/home/xxx/yyy", "&&", "pwd"])

But during execution it's found that buildbot processes it as below, which makes it impossible to execute

sh -c pwd '&&' cd /home/xxx/yyy '&&' pwd

What I expected is

sh -c pwd && cd /home/xxx/yyy && pwd

Could anyone help me out of this please? Thanks.

like image 290
Di Liu Avatar asked Aug 14 '14 12:08

Di Liu


1 Answers

Since you're using /bin/sh anyway just call it with a single string:

f1.addStep(shell.ShellCommand, command="pwd && cd /home/xxx/yyy && pwd")

As documentation says:

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.

It's not recommended but you'd still need the shell anyway as && is only interpreted within the shell. Calling sh would just be redundant.

like image 153
konsolebox Avatar answered Oct 17 '22 02:10

konsolebox