2

I am using lintr library in R to find linting issues in the code. I put them into an xml format like this:

<lintsuites>
  <lintissue filename="/home/.../blah.R" line_number="36" column_number="1" type="style" message="Trailing blank lines are superfluous."/>
  <lintissue filename="/home/.../blahblah.R" line_number="1" column_number="8" type="style" message="Only use double-quotes."/>
</lintsuites>

Now, I would like to fail the Azure devops build when issues like this occur.

I was able to get my tests in a JUnit format like this:

  <testsuite name="MB Unit Tests" timestamp="2020-01-22 22:34:07" hostname="0000" tests="29" skipped="0" failures="0" errors="0" time="0.05">
    <testcase time="0.01" classname="1_Unit_Tests" name="1_calculates_correctly"/>
    <testcase time="0.01" classname="1_Unit_Tests" name="2_absorbed_correctly"/>
...
</testsuite>

And when i do this step in the azure pipeline, my build fails if any tests in the test suite fail:

  - task: PublishTestResults@2
    displayName: 'Publish Test Results'
    inputs:
      testResultsFiles: '**/*.xml'
      searchFolder: '$(System.DefaultWorkingDirectory)/fe'
      mergeTestResults: true
      failTaskOnFailedTests: true

I would like something similar for failing the build when there are linting issues. I would also like the users to see what those linting issues are in the build output. Thanks

Wanderer
  • 21
  • 3

1 Answers1

0

This is not possible to achieve a similar result for lintr xml with plishTestResults@2.

The workaround you can try is to use a powershell task to check for the content of your lintr xml file. If the content isnot empty, then fail the pipeline in the powershell task.

Below powershell task will check the content of lintr.xml(<car></car>) and will echo the content to the task logs and exit 1 to fail the task if the content is null.

 - powershell: |
        [xml]$XmlDocument = Get-Content -Path "$(system.defaultworkingdirectory)/lintr.xml"

        if($XmlDocument.OuterXml){
           echo $XmlDocument.OuterXml
          }else{exit 1}

   displayName: lintr result.

enter image description here

You can aslo use below statement in a powershell task to upload lintr xml file to the build summary page where you can download

echo "##vso[task.uploadsummary]$(system.defaultworkingdirectory)/lintr.xml"

You can check here for more logging commands.

Update:

A workaround to show the lintr results in a nice way is to create a custom extension to display html results in azure devops pipeline.

You can try creating a custom extension, and produce a html lint results. Please refer to the answer to this thread an example custom extension to display html

Other developers already submit requests to Microsoft for implementing this feature. Please vote it up here or create a new one.

Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
  • Yes. thanks a lot. Since i work in a Linux environment i wrote a bash task instead of a powershell task. However, i'd be interested to know how to see the results of the lint issues in a nice way. The only thing i can think of is publishing the resultant xml as an artifact. – Wanderer Jan 27 '20 at 20:30
  • There is a way that you can create a custom extension to display the lint xml. Check my update. – Levi Lu-MSFT Jan 28 '20 at 02:16
  • Hi @Wanderer did you check out above update and have a try with the custom extension, how did it go? – Levi Lu-MSFT Feb 03 '20 at 14:06
  • No. Did not get a chance to try it out. – Wanderer Feb 03 '20 at 21:29
  • Hi @Wanderer if you get time to test it, feel free to let me know how it is going. – Levi Lu-MSFT Feb 06 '20 at 15:56