0

Having a Bitbucket pipeline that executes 2 steps:

  1. Runs Python tests and saves report artifacts in an XML file
  2. Runs SonarQube scanner with the above report file.

If every test is ok, the SonarQube task runs and uploads everything. If any tests fail, the "SonarQube Scan" step doesn't run as expected.

Is it possible to run the "SonarQube Scan" step anyway without considering the failure of the previous one (test)? The total execution of the pipeline should be considered as FAILED (RED) when tests fail.

1 Answer 1

1

I solved the problem by using the after-script section. My bitbucket-pipelines.yml looks like:

image: python:3.8

pipelines:
  default:
    - step:
        name: Execute Tests & Upload to Sonar
        script:
          - pip install poetry
          - poetry config virtualenvs.create false
          - poetry install
          - poetry run pytest
        artifacts:
          - test_report.xml
          - coverage.xml
        after-script:
          - pipe: sonarsource/sonarqube-scan:1.0.0
            variables:
              SONAR_HOST_URL: ${SONAR_HOST_URL}
              SONAR_TOKEN: ${SONAR_TOKEN}

Not the answer you're looking for? Browse other questions tagged or ask your own question.