0

I have a command line task running in windows image of Azure DevOps pipeline. This task after performing pmd.bat command exiting with code 4. Where as this runs perfectly fine in my local CMD.

 task: CmdLine@2
  inputs:
   script:  |
       echo starting  execution
       cd $(Build.SourcesDirectory)
       xcopy *.jar $(Build.SourcesDirectory)\code\
       cd $(Build.SourcesDirectory)\pmd-bin-6.24.0\bin
       pmd.bat -d "$(Build.SourcesDirectory)\code\src\apexcode.cls" -f xml -R "$(Build.SourcesDirectory)\code\build\MyApexRule.xml" -reportfile pmd.xml

Can anyone help me with what can be the issue?

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
priya
  • 391
  • 1
  • 5
  • 24

2 Answers2

0

Exiting with code 4 in PMD suggests at least one violation has been detected.

Here are two solutions to make the command work:

  1. You can set the parameter <failurePriority> to 1 (its default value is 5), so that all violations will be seen as a warning and will be displayed in the build output. And then you can see where the command goes wrong.

  2. You can set the parameter <failOnViolation> to false (its default value is true), so that the commands won't fail even if if the validation check fails. The only difference from solution 1 is that no warning messages are displayed.

You can set the parameters in POM file:

<build>
 <plugins>
  <plugin>
    <failurePriority>1</failurePriority>
    <failOnViolation>false</failOnViolation>
  </plugin>
 </plugins>
</build>

or set them as properties on pmd.bat inline script.

Jane Ma-MSFT
  • 4,461
  • 1
  • 6
  • 12
  • No, the issue doesn't seem to be xcopy error because I can see in the log, the xcopy step worked fine and the file is copied proper. – priya Aug 17 '20 at 06:12
  • starting execution D:apexcustom-rule-1.0.0-SNAPSHOT.jar 1 File(s) copied Successfully processed 8 files; Failed processing 0 files D:\a\1\s\code\build\ D:\a\1\s\pmd-bin-6.24.0\bin\.. D:\a\1\s Aug 17, 2020 6:10:15 AM net.sourceforge.pmd.PMD encourageToUseIncrementalAnalysis WARNING: This analysis could be faster, please consider using Incremental Analysis: https://pmd.github.io/pmd-6.24.0/pmd_userdocs_incremental_analysis.html ##[error]Cmd.exe exited with code '4'. Finishing: CmdLine – priya Aug 17 '20 at 06:13
  • @priya Exiting without an error message is quite weird. Have you ever tried to run the task without `pmd.pat` command? – Jane Ma-MSFT Aug 17 '20 at 08:12
  • the purpose of the task was to execute the pmd.bat and generate the reportfile...this is working fine in my local...so no issues with the bat file..am unable to understand why is it exiting and failing the task – priya Aug 17 '20 at 08:18
  • @priya Exiting with code 4 in PMD suggests at least one violation has been detected. You can set the parameter `` to 1 (its default value is 5), so that all violations will be seen as a warning and will be displayed in the build output. And then you can see where the command goes wrong. – Jane Ma-MSFT Aug 17 '20 at 09:15
  • where can I specify this parameter? in rule.xml? – priya Aug 17 '20 at 11:04
  • My Custom Rule Method should not have more than 60 lines of code. 3 – priya Aug 17 '20 at 11:06
  • thankyou for the suggestion.. I have included failonviolation property as false on the pmd.bat inline script line ..now it works good without any issue – priya Aug 17 '20 at 11:47
  • Done.Thanks again – priya Aug 18 '20 at 06:44
  • hello, can u help me with this question? thanks in advance -> https://stackoverflow.com/questions/63468067/pmd-analysis-for-multiple-files – priya Aug 18 '20 at 11:58
0

As Jane Ma-MSFT correctly explained, exit code 4 means, there are some violations detected and the build is failed.

See https://pmd.github.io/latest/pmd_userdocs_cli_reference.html#exit-status for the documentation.

4: At least one violation has been detected, unless -failOnViolation false is set.

You could adjust your script to add -failOnVioltation false if you never want the build to fail and just want to have the report generated:

Specifies whether PMD exits with non-zero status if violations are found. By default PMD exits with status 4 if violations are found. Disable this feature with -failOnViolation false to exit with 0 instead and just output the report.

adangel
  • 1,816
  • 14
  • 17