0

In the Execute shell command option in Jenkins I am trying to execute xcodebuild -scheme "My project" test | xcpretty --report junit --output report.xml

But when Jenkins executes it, it looks like it does not recognize the pipe character and it takes it as next line or something.

Things I have tried - Putting the command in a .sh file - Escaping the pipe character - Use Eval

None of them have worked

I do not want to use the Xcode plugin for the moment.

Any tips to make it work?

Kenenisa Bekele
  • 835
  • 13
  • 34

2 Answers2

1

Try putting #!/bin/bash at the top of your command-line code. (Please don't make the wrong spelling.)

EDIT: If it is not the pipe, then it could be that you need to take the output of the first command and wrap it so it sends it all at once... I might be wording that wrong.

OUT="$(xcodebuild -scheme "My project" test)"
echo $OUT | xcpretty --report junit --output report.xml
Fred Li
  • 3
  • 2
Jose Martinez
  • 11,452
  • 7
  • 53
  • 68
  • Did not work, same thing, I also tried putting it in the .sh file I created. – Kenenisa Bekele Apr 30 '18 at 13:34
  • Hmm, let me do a test on my local Jenkins. – Jose Martinez Apr 30 '18 at 13:46
  • I execute the following command in the "Execute shell" section of Jenkins.. `echo "hello" | grep "hello"`. There were no problems at all. Maybe the issue is not with pipes? – Jose Martinez Apr 30 '18 at 14:13
  • Maybe, still have not found the way to fix it. – Kenenisa Bekele Apr 30 '18 at 17:52
  • 1
    it looks like the problem was xcpretty, adding export LC_CTYPE=en_US.UTF-8 worked, found the solution in https://github.com/supermarin/xcpretty/issues/48. Thanks Jose for diagnostic – Kenenisa Bekele Apr 30 '18 at 18:25
  • In my test, adding `#!/bin/bash` works, **BUT need to pay attention**, say we're running multi-line shell scripts with triple quotes, need to place the shebang at the right side of the `"""`, not at the next line of the `"""`. – MadHatter Jun 02 '23 at 08:41
0

It looks like it's treating it as a newline because both commands are actually being executed at the same time; they are not executed sequentially. See What is a simple explanation for how pipes work in Bash?

mamills
  • 1,786
  • 1
  • 15
  • 15