diff --git a/changelogs/fragments/40174-junit-test-case-prefix-filter.yaml b/changelogs/fragments/40174-junit-test-case-prefix-filter.yaml new file mode 100644 index 0000000000..d0ff10ce68 --- /dev/null +++ b/changelogs/fragments/40174-junit-test-case-prefix-filter.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: +- junit callback plug-in - introduce a new option to consider a task only as test case if it has this value as prefix. diff --git a/lib/ansible/plugins/callback/junit.py b/lib/ansible/plugins/callback/junit.py index 3492f55305..a7f106a1b3 100644 --- a/lib/ansible/plugins/callback/junit.py +++ b/lib/ansible/plugins/callback/junit.py @@ -65,6 +65,13 @@ DOCUMENTATION = ''' version_added: "2.8" env: - name: JUNIT_HIDE_TASK_ARGUMENTS + test_case_prefix: + name: Prefix to find actual test cases + default: + description: Consider a task only as test case if it has this value as prefix. Additionaly failing tasks are recorded as failed test cases. + version_added: "2.8" + env: + - name: JUNIT_TEST_CASE_PREFIX requirements: - whitelist in configuration - junit_xml (python lib) @@ -122,6 +129,9 @@ class CallbackModule(CallbackBase): Default: True JUNIT_HIDE_TASK_ARGUMENTS (optional): Hide the arguments for a task Default: False + JUNIT_TEST_CASE_PREFIX (optional): Consider a task only as test case if it has this value as prefix. Additionaly failing tasks are recorded as failed + test cases. + Default: Requires: junit_xml @@ -143,6 +153,7 @@ class CallbackModule(CallbackBase): self._fail_on_ignore = os.getenv('JUNIT_FAIL_ON_IGNORE', 'False').lower() self._include_setup_tasks_in_report = os.getenv('JUNIT_INCLUDE_SETUP_TASKS_IN_REPORT', 'True').lower() self._hide_task_arguments = os.getenv('JUNIT_HIDE_TASK_ARGUMENTS', 'False').lower() + self._test_case_prefix = os.getenv('JUNIT_TEST_CASE_PREFIX', '') self._playbook_path = None self._playbook_name = None self._play_name = None @@ -211,7 +222,8 @@ class CallbackModule(CallbackBase): elif status == 'ok': status = 'failed' - task_data.add_host(HostData(host_uuid, host_name, status, result)) + if task_data.name.startswith(self._test_case_prefix) or status == 'failed': + task_data.add_host(HostData(host_uuid, host_name, status, result)) def _build_test_case(self, task_data, host_data): """ build a TestCase from the given TaskData and HostData """