-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DevOps Publish Test Results Task Fails #1
Comments
This doesn't look like a problem related to the handlebars template. The error is related to the scanner not being able to publish the result files. Normally this happens on a self-hosted agent that has a version of docker installed via the SNAP package manager. Are you by any chance running a similar self-hosted agent @carllp ? |
@doymturner The agent the task is being run on is the Ubuntu 18.04 Microsoft-hosted agent. |
Can you share your full pipeline (cleansed)? At least all of the bits related to zap scanner? |
Sure. I believe it's been sufficiently cleansed of all unique identifiers. As a side note, if you could point me to some documentation (via DM or here) to speed up the cleansing of pipeline logs it would be much appreciated. |
Took a second look at the original error you posted. Did you make any changes to the handlebar template when adding it to your pipeline? Could you share the bits of your pipeline YAML related to the extension and report publishing (including the template)? FYI: We are working on additional reporting options for the extension, but plan to leave the options for custom reporting such as with the handlebars template so I'm keen to figure out the issue. |
As requested, 1st snippet is the handlebars YAML and the 2nd is the report conversion. 3rd is the Publish Test Results YAML. steps:
steps:
steps:
|
Error in the publish test results task is slightly different now. It now shows: Instead of Full log: ` ##[section]Starting: Publish Test Results test-results.xml Task : Publish Test Results [command]/usr/bin/dotnet --version |
I have the same issue as carllp and I have solved it by creating whole task in yaml instead of DevOps separate components. |
@carllp Take a look in your test-results.xml file (copy it to artifacts so you can download it), it likely has 2 I've opened an issue for it as the script itself is written to do this specifically for each site that is scanned, in my case it was http vs https |
So how did you resolve the issue? NM. Thanks! |
The sample shows the following sudo npm install -g handlebars-cmd cat < owaspzap/nunit-template.hbs ... snip EOF When running in a bash task this causes failure. Fix by moving everything from cat to EoF two spaces to the left. |
hi I am not able to see test tab eventhough build is successful |
trigger:
pool: steps:
displayName: 'owasp nunit template'
|
Can anyone help me |
I've found solution for this, I'll just paste it from marketplace reviews. Sithu Kyaw After a couple of troubleshooting, I found Handlebars script needs minor adjustment by adding $(System.DefaultWorkingDirectory)/ in front of 'owasp/report.html' inside . Good work!
|
In Step 1 - Remove the EOF statement at the end. Keep only the below code. It will work fine sudo npm install -g handlebars-cmd
$(System.DefaultWorkingDirectory)/owaspzap/report.html
|
I have had the same problem, tried all different possibilites. But always get error file not found..
also by injecting env variable to xslt
also added echo to confirm the location of file
/home/vsts/work/1/s/OWASP-ZAP-Report.xml |
In my case the pipeline runs successfully. However the Passed test results are not shown in the test report. I only see the failed or others. This is the template I am using. stages:
|
Hello everyone! I'm don't use this extension for ZAP testing, but got the same issue - unable to upload test results. So my pipeline yaml looks like this: trigger: none
pr: none
pool:
vmImage: ubuntu-latest
steps:
- script: docker run --rm --user root -v $(System.DefaultWorkingDirectory):/zap/wrk/:rw -i owasp/zap2docker-stable zap-full-scan.py -d -j -I -t https://blah-blah -J owasp-zap/zap-report.json
displayName: 'Run dynamic testing'
- bash: |
sudo npm install -g handlebars-cmd
handlebars owasp-zap/zap-report.json < owasp-zap/nunit-template.hbs > owasp-zap/test-results.xml
python3 owasp-zap/splitter.py test-results.xml
displayName: 'Generate test result files'
- task: PublishTestResults@2
displayName: 'Publish rest results'
inputs:
testResultsFormat: NUnit
testResultsFiles: 'owasp-zap/test-results-*.xml'
mergeTestResults: true So, at the root of my repo i had directory owasp-zap that contains file nunit-template.hbs: {{#each site}}
<test-run
id="2"
name="Owasp test"
start-time="{{../[@generated]}}" >
<test-suite
id="{{@index}}"
type="Assembly"
name="{{[@name]}}"
result="Failed"
failed="{{alerts.length}}">
{{#each alerts}}<test-case
id="{{@index}}"
name="{{alert}}"
result="Failed"
fullname="{{alert}}"
time="1">
<failure>
<message>
<![CDATA[{{{desc}}}]]>
</message>
<stack-trace>
<![CDATA[
Solution:
{{{solution}}}
Reference:
{{{reference}}}
instances:{{#each instances}}
* {{uri}}
- {{method}}
{{#if evidence}}- {{{evidence}}}{{/if}}
{{/each}}]]>
</stack-trace>
</failure>
</test-case>
{{/each}}
</test-suite>
</test-run>
{{/each}} And file splitter.py: import xml.dom.minidom as minidom
import argparse
def parse_file():
parser = argparse.ArgumentParser(description='File path parser')
parser.add_argument('-f', '--file', type=str, help='A required string - path to report file.')
args = parser.parse_args()
return args.file
def get_xml(document: str) -> list:
with open(document, 'r') as file:
return [line for line in file]
def to_file(line: str, file_name: str):
with open(file_name, 'a') as f:
f.write(line)
def extract_separate_documents(lines: list):
count = 0
for line in lines:
line: str
if '<test-run' in line:
count += 1
print('report:', count)
if count > 0:
to_file(line, f'test-results-{count}.xml')
document = parse_file()
if not document:
print("Exception! Report file not specified.")
exit(1)
lines = get_xml(document=document)
extract_separate_documents(lines) My ZAP testing run generates json file, that should be procced by handlebars tool and I got test-results.xml in owasp-zap dir. In my case test-results.xml file contains two root block that doesn't correspond to NUnit type. Than I wrote a Python script that splits this xml result file on more files named test-results-{count}.xml based on tag. And in PublishTestResults task i provided those files as an input and set mergeTestResults parameter to true. This is working fine in my case and may be suitable for yours. |
Hello,
Receiving the following error in the Publish Test Results task after successfully running both Bash scripts as found on your reporting documentation (https://marketplace.visualstudio.com/items?itemName=CSE-DevOps.zap-scanner). Test results are not shown on the test tab even though the task is marked as having succeeded.:
2019-12-05T14:36:03.5747957Z ##[debug]OS type: Linux
2019-12-05T14:36:04.4503434Z ##[debug]Reading test results from file '/home/vsts/work/r1/a/owaspzap/test-results.xml'
2019-12-05T14:36:04.4569568Z ##[warning]Failed to read /home/vsts/work/r1/a/owaspzap/test-results.xml. Error : Data at the root level is invalid. Line 22, position 4..
2019-12-05T14:36:04.4591686Z ##[warning]Failed to publish test results: Object reference not set to an instance of an object.
2019-12-05T14:36:04.4717111Z ##[debug]Processed: ##vso[results.publish type=NUnit;mergeResults=false;publishRunAttachments=true;resultFiles=/home/vsts/work/r1/a/owaspzap/test-results.xml;failTaskOnFailedTests=false;testRunSystem=VSTS - PTR;]
2019-12-05T14:36:04.4718265Z ##[debug]task result: Succeeded
2019-12-05T14:36:04.4718634Z ##[debug]Processed: ##vso[task.complete result=Succeeded;]
As a possible alternative solution if handlebars is causing issues, perhaps outputting the test results file as an .xml and then using the template found on this azuredevblog might work?
https://devblogs.microsoft.com/premier-developer/azure-devops-pipelines-leveraging-owasp-zap-in-the-release-pipeline/
Thanks for your time! Appreciate your work.
The text was updated successfully, but these errors were encountered: