|
35 | 35 | register: verbose_matches |
36 | 36 | ignore_errors: true |
37 | 37 |
|
| 38 | + # The RC from grep is 2 if an error occurred. |
| 39 | + - name: Fail if the file was not found (or other grep error) |
| 40 | + ansible.builtin.fail: |
| 41 | + msg: "{{ verbose_matches.stderr if verbose_matches.stderr | length > 0 else 'There was an error with grep.' }}" |
| 42 | + when: verbose_matches.rc > 1 |
| 43 | + |
38 | 44 | - name: "Fail if there are no XML files" |
39 | 45 | ansible.builtin.fail: |
40 | 46 | msg: "There were no XML files found in {{ logs_dir }}." |
41 | 47 | when: verbose_matches.stdout_lines | length == 0 |
42 | 48 |
|
43 | | - - name: "Get the number of failed testcases" |
| 49 | + - name: "Get the number of testcase errors and failures" |
44 | 50 | ansible.builtin.set_fact: |
| 51 | + tasks_errored: "{{ verbose_matches.stdout | regex_replace('.*errors=\"([0-9]*)\".*>', '\\1') | split('\n') | map('int') | sum }}" |
45 | 52 | tasks_failed: "{{ verbose_matches.stdout | regex_replace('.*failures=\"([0-9]*)\".*>', '\\1') | split('\n') | map('int') | sum }}" |
46 | 53 |
|
47 | 54 | # The RC from grep is 0 if the string is matched |
48 | | - - name: Fail when there's a testcase failure |
| 55 | + - name: Fail when there's a testcase error |
49 | 56 | ansible.builtin.fail: |
50 | | - msg: There were {{ tasks_failed }} failed testcases. |
51 | | - when: tasks_failed | int > 0 and verbose_matches.rc == 0 |
| 57 | + msg: There were {{ tasks_errored }} errors in the testcases. |
| 58 | + when: tasks_errored | int > 0 and verbose_matches.rc == 0 |
52 | 59 |
|
53 | | - - name: Determine success or failure based on the number of failed tasks |
54 | | - ansible.builtin.fail: |
55 | | - msg: "The log file(s) contain failed task." |
56 | | - when: tasks_failed | int > 0 and verbose_matches.rc == 0 |
57 | | - |
58 | | - # The RC from grep is 2 if an error occurred. |
59 | | - - name: Fail if the file was not found (or other grep error) |
| 60 | + # The RC from grep is 0 if the string is matched |
| 61 | + - name: Fail when there's a testcase failure |
60 | 62 | ansible.builtin.fail: |
61 | | - msg: "{{ verbose_matches.stderr if verbose_matches.stderr | length > 0 else 'There was an error with grep.' }}" |
62 | | - when: verbose_matches.rc > 1 |
| 63 | + msg: There were {{ tasks_errored }} errors and {{ tasks_failed }} failed testcases. |
| 64 | + when: ( [ tasks_failed, tasks_errored ] | sum > 0 ) and verbose_matches.rc == 0 |
0 commit comments