0

I have to create a job in my local Jenkins installation where it executes a SonarQube analysis and then calls a command-line program which searches for duplicated lines of code. However, when I execute the latter command (cpd), it runs okay since it outputs correctly in a external file, but Jenkins still points out it as an error like this:

E:\BASE_DIR>cpd --minimum-tokens 100 --files "E:\BASE_DIR\Project_Folder" --language java  1>>"E:\BASE_DIR\Project_Folder\CPD_CLIG.txt" 

Build step 'Execute shell' marked build as failure
Finished: FAILURE 

I've tried to create another script which calls that command but I've got the same result.

Any suggestions on how to handle this? Any work-around would be very helpful.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

1

Simple and short answer to your question is

Please add following line into your "Execute shell" Build step.

"#!/bin/sh"

Now let me explain you the reason why we require this line for "Execute Shell" build job.

By default Jenkins take "/bin/sh -xe" and this means -x will print each and every command.And the other option -e, which causes shell to stop running a script immediately when any command exits with non-zero(when any command fails) exit code.

So by adding the "#!/bin/sh" will allow you to execute with no option.

please refer : How/When does Execute Shell mark a build as failure in Jenkins?

Community
  • 1
  • 1
Abhijeet Kamble
  • 3,131
  • 2
  • 30
  • 36
  • Thanks for replying @AbhijeetKamble. However, I really have to run this on windows, since the server in my company is windows-based. But thanks anyway, it may give a light on my issue. – jeffersonlsz Jun 17 '15 at 17:10
0

I didn't find a proper solution for my issue but I realized that I can use a Jenkins plugin for static code analysis (DRY Plugin and PMD Plugin) to adress my problem.

Thanks you all.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129