|
19 | 19 | vars_files: |
20 | 20 | - vars/common.yml |
21 | 21 | tasks: |
22 | | - - name: "Find the XML file" |
| 22 | + - name: "Find the XML file(s)" |
23 | 23 | ansible.builtin.shell: |
24 | 24 | cmd: | |
25 | | - find ~/.ansible.log/ -name *.xml |
| 25 | + find {{ custom_xml_output_dir }} -name *.xml |
26 | 26 | register: xml_file_list |
27 | 27 | ignore_errors: true |
28 | 28 |
|
|
54 | 54 | src: "{{ ansible_env.HOME }}/summary_results.log" |
55 | 55 | dest: "{{ logs_dir }}/summary_result.log" |
56 | 56 |
|
57 | | -- name: "Check the results files for failed tasks" |
| 57 | +- name: Check the XML file for failed tasks |
58 | 58 | hosts: controller |
59 | 59 | gather_facts: true |
60 | 60 | vars_files: |
61 | 61 | - vars/common.yml |
62 | 62 | tasks: |
63 | | - - name: Grep the number of failed tasks |
64 | | - ansible.builtin.shell: |
65 | | - cmd: | |
66 | | - grep "failed" {{ logs_dir }}/test_run_result.out |
67 | | - register: tasks_failed |
68 | | - # The RC from grep is 1 when there is no string matched (i.e. when there are no failures) |
69 | | - ignore_errors: yes |
| 63 | + - name: "Get the matching lines in the results files" |
| 64 | + ansible.builtin.command: |
| 65 | + cmd: | |
| 66 | + grep -r "<testsuites .*>$" {{ custom_xml_output_dir }}/ |
| 67 | + register: verbose_matches |
| 68 | + ignore_errors: true |
| 69 | + |
| 70 | + - name: "Get the number of failed testcases" |
| 71 | + ansible.builtin.set_fact: |
| 72 | + tasks_failed: "{{ verbose_matches.stdout | regex_replace('.*failures=\"([0-9]*)\".*>', '\\1') | split('\n') | map('int') | sum }}" |
70 | 73 |
|
71 | 74 | # The RC from grep is 0 if the string is matched |
| 75 | + - name: Fail when there's a testcase failure |
| 76 | + ansible.builtin.fail: |
| 77 | + msg: There were {{ tasks_failed }} failed testcases. |
| 78 | + when: tasks_failed | int > 0 and verbose_matches.rc == 0 |
| 79 | + |
72 | 80 | - name: Determine success or failure based on the number of failed tasks |
73 | 81 | ansible.builtin.fail: |
74 | 82 | msg: "The log file(s) contain failed task." |
75 | | - when: tasks_failed.stdout_lines | length > 0 and tasks_failed.rc == 0 |
| 83 | + when: tasks_failed | int > 0 and verbose_matches.rc == 0 |
76 | 84 |
|
77 | 85 | # The RC from grep is 2 if an error occurred. |
78 | 86 | - name: Fail if the file was not found (or other grep error) |
79 | 87 | ansible.builtin.fail: |
80 | | - msg: "{{ tasks_failed.stderr if tasks_failed.stderr | length > 0 else 'There was an error with grep.' }}" |
81 | | - when: tasks_failed.rc > 1 |
| 88 | + msg: "{{ verbose_matches.stderr if verbose_matches.stderr | length > 0 else 'There was an error with grep.' }}" |
| 89 | + when: verbose_matches.rc > 1 |
0 commit comments