|
| 1 | +# Template Handling in junit2json Role |
| 2 | + |
| 3 | +## The Problem |
| 4 | + |
| 5 | +Test data sometimes contains literal strings that look like Jinja2 templates: |
| 6 | + |
| 7 | +```xml |
| 8 | +<testcase name="... expectations failed: {{ expectation_failed }}" /> |
| 9 | +<testcase name="... log at: https://ci.example.com/jobs/{{ job_info.job.id }}/states" /> |
| 10 | +``` |
| 11 | + |
| 12 | +When Ansible processes this data, it tries to evaluate these as templates, causing: |
| 13 | + |
| 14 | +``` |
| 15 | +ERROR! 'expectation_failed' is undefined |
| 16 | +ERROR! 'job_info' is undefined |
| 17 | +``` |
| 18 | + |
| 19 | +## The Solution |
| 20 | + |
| 21 | +The role provides dummy variables for template patterns. Which method you use depends on **variable frequency** and **your maintenance access**: |
| 22 | + |
| 23 | +## Adding Dummy Variables |
| 24 | + |
| 25 | +### High Frequency Variables (appear across many teams/projects) |
| 26 | + |
| 27 | +**If you maintain the role:** |
| 28 | +Edit `vars/dummy_variables.yml`: |
| 29 | + |
| 30 | +```yaml |
| 31 | +junit2_dummy_variables: |
| 32 | + # Add variables that many teams encounter |
| 33 | + common_variable: "PLACEHOLDER_COMMON_VARIABLE" |
| 34 | + shared_info: |
| 35 | + build_id: "PLACEHOLDER_BUILD_ID" |
| 36 | +``` |
| 37 | +
|
| 38 | +**If you don't maintain the role:** |
| 39 | +Request the role maintainer to add these variables to `vars/dummy_variables.yml`. |
| 40 | + |
| 41 | +### Low Frequency Variables (specific to your team/project) |
| 42 | + |
| 43 | +**If you maintain the playbook:** |
| 44 | +Add variables when calling the role: |
| 45 | + |
| 46 | +```yaml |
| 47 | +- name: Convert test reports |
| 48 | + ansible.builtin.include_role: |
| 49 | + name: junit2json |
| 50 | + vars: |
| 51 | + junit2_custom_dummy_variables: |
| 52 | + # Add team-specific variables |
| 53 | + pipeline_id: "PLACEHOLDER_PIPELINE_ID" |
| 54 | + deployment: |
| 55 | + environment: "PLACEHOLDER_ENVIRONMENT" |
| 56 | +``` |
| 57 | + |
| 58 | +**If you don't maintain the playbook:** |
| 59 | +Create an external variables file `my_extras.yml`: |
| 60 | + |
| 61 | +```yaml |
| 62 | +junit2_custom_dummy_variables: |
| 63 | + pipeline_id: "PLACEHOLDER_PIPELINE_ID" |
| 64 | + deployment: |
| 65 | + environment: "PLACEHOLDER_ENVIRONMENT" |
| 66 | +``` |
| 67 | + |
| 68 | +Run with: |
| 69 | + |
| 70 | +```shell |
| 71 | +ansible-playbook my_playbook.yml -e @my_extras.yml |
| 72 | +``` |
| 73 | + |
| 74 | +### Debug Mode |
| 75 | + |
| 76 | +Enable debug to see what variables are being set: |
| 77 | + |
| 78 | +```yaml |
| 79 | +junit2_dummy_debug: true |
| 80 | +``` |
| 81 | + |
| 82 | +## Role Maintenance & Feedback |
| 83 | + |
| 84 | +**This role is maintained by:** GitHub team `@redhatci/verification` |
| 85 | + |
| 86 | +**Help us improve:** Please share your custom dummy variables with the maintenance team! When you add variables using `junit2_custom_dummy_variables` or external files, let `@redhatci/verification` know what variables you needed. This helps us identify high-frequency variables that should be moved into the role for everyone's benefit. |
| 87 | + |
| 88 | +## Variables Already Handled |
| 89 | + |
| 90 | +These patterns are already handled (may change based on test data encountered): |
| 91 | + |
| 92 | +- `{{ expectation_failed }}` |
| 93 | +- `{{ job_info.job.id }}` |
| 94 | +- `{{ ci_job_id }}` |
| 95 | +- `{{ error_message }}` |
| 96 | +- `{{ timestamp }}` |
0 commit comments