--- # Copyright Red Hat, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - name: Check if variables are defined and not empty ansible.builtin.assert: that: - cifmw_polarion_jump_repo_url is defined and cifmw_polarion_jump_repo_url != "" - cifmw_polarion_testrun_id is defined and cifmw_polarion_testrun_id != "" - name: Ensure deps are installed become: true tags: - bootstrap - packages ansible.builtin.package: name: "{{ cifmw_polarion_deps }}" state: present - name: Look for test result XML files in artifacts directory ansible.builtin.find: paths: "{{ cifmw_polarion_jump_result_dir }}" patterns: "*.xml" recurse: true register: xml_files - name: Deploy jump and report to polarion when: xml_files.files | length > 0 block: - name: Validate XML files with xmllint ansible.builtin.command: "xmllint --noout {{ item.path }}" loop: "{{ xml_files.files }}" register: xmllint_output changed_when: false failed_when: xmllint_output.rc != 0 - name: Clone Jump repository ansible.builtin.git: repo: "{{ cifmw_polarion_jump_repo_url }}" dest: "{{ cifmw_polarion_jump_repo_dir }}" version: "{{ cifmw_polarion_jump_repo_branch }}" force: true - name: Create virtualenv when: - cifmw_polarion_jump_repo_dir is defined and cifmw_polarion_jump_repo_dir != "" ansible.builtin.pip: name: pip virtualenv: "{{ cifmw_polarion_jump_repo_dir }}/jump-venv" virtualenv_command: "/usr/bin/python3 -m venv" state: latest # noqa: package-latest extra_args: --upgrade - name: Install junitparser ansible.builtin.pip: name: junitparser virtualenv: "{{ cifmw_polarion_jump_repo_dir }}/jump-venv" state: latest # noqa: package-latest - name: Use polarion-staging when: - cifmw_polarion_use_stage - cifmw_polarion_fqdn is defined and cifmw_polarion_fqdn != "" - cifmw_polarion_stage_fqdn is defined and cifmw_polarion_stage_fqdn != "" ansible.builtin.replace: path: "{{ cifmw_polarion_jump_repo_dir }}/{{ item }}" regexp: "{{ cifmw_polarion_fqdn }}" replace: "{{ cifmw_polarion_stage_fqdn }}" loop: - ".pylero" - name: Check if pylero is already present ansible.builtin.stat: path: "{{ cifmw_polarion_jump_repo_dir }}/pylero" register: pylero_stat - name: Run prepare_pylero.sh ansible.builtin.shell: > source jump-venv/bin/activate && \ ./prepare_pylero.sh args: chdir: "{{ cifmw_polarion_jump_repo_dir }}" executable: /bin/bash register: pylero_output when: not pylero_stat.stat.exists - name: Output prepare_pylero ansible.builtin.debug: var: pylero_output.stdout_lines when: not pylero_stat.stat.exists - name: Merge result XML files of each directory ansible.builtin.shell: chdir: "{{ cifmw_polarion_jump_result_dir }}" cmd: >- source "{{ cifmw_polarion_jump_repo_dir }}/jump-venv/bin/activate" && junitparser merge {{ item.path | dirname }}/*.xml {{item.path | dirname }}/results_merged.xml loop: "{{ xml_files.files | sort(attribute='path') }}" - name: Look for test result XML files in artifacts directory ansible.builtin.find: paths: "{{ cifmw_polarion_jump_result_dir }}" patterns: "results_merged.xml" recurse: true register: merged_xml_files - name: Update Test Runs vars: _opts: cijoburl: "{{ cifmw_zuul_url }}/{{ zuul.build }}" jobteststage: "{{ merged_xml_files.files[ loop_idx ].path | dirname | basename }}" _custom_fields: "{{ _opts | combine(cifmw_polarion_jump_custom_fields) }}" _custom_fields_string: >- {{ _custom_fields.keys() | zip(_custom_fields.values()) | map('join', '=') | join(',') }} ansible.builtin.shell: chdir: "{{ cifmw_polarion_jump_repo_dir }}" cmd: >- source "{{ cifmw_polarion_jump_repo_dir }}/jump-venv/bin/activate" && {{ cifmw_polarion_jump_repo_dir }}/jump-venv/bin/python jump.py --testrun-id={{ cifmw_polarion_testrun_id }} --testrun-title={{ cifmw_polarion_testrun_title }}-{{ loop_idx }} --xml-file={{ item.path }} --update_testcases={{ cifmw_polarion_update_testcases | default(false) }} --custom-fields {{ _custom_fields_string | quote }} {{ cifmw_polarion_jump_extra_vars | default ('') }} loop: "{{ merged_xml_files.files }}" loop_control: index_var: loop_idx register: jump_script - name: Output of jump ansible.builtin.debug: var: jump_script.stderr_lines always: - name: Remove merged xml files ansible.builtin.file: path: "{{ item.path }}" state: absent loop: "{{ merged_xml_files.files }}"