Bitbucket pipeline not uploading to Codecov within pull request

Before submitting a topic, please confirm the following

I have searched for similar issues before creating this topic.
I have verified that my repository is using the Codecov GitHub app, if using GitHub
I have validated my codecov.yaml configuration file.
I have filled out the below sections to the best of my ability.
I understand that the community boards are a free, best-effort tool. While we hope to have someone on the Codecov team resolve your problem quickly, this is not always possible.

Description

When using bitbucket pipelines to run a coverage report (PHPunit). I have debugged to the best of my ability what could be failing. It works as intended when I use the “default” pipeline, but when I use the “pull-request” pipeline it seems to fail to upload. When I compare the pipeline builds, within the codecov step it appears the 2 URLs differ with the parameters. A working build contains a build URL and a commit, whereas the failing build has empty variables for these.
The desirable outcome is that we only want to run code coverage reports on pull requests to the testing branch and not every branch commit.

CI/CD URL

Private bitbucket pipeline.

Codecov Output

Please provide the full output of running the uploader on your CI/CD. This will typically have the Codecov logo as ASCII.

+ ./codecov --verbose
[2023-05-03T12:54:45.935Z] ['verbose'] Start of uploader: 1683118485935...
[2023-05-03T12:54:45.937Z] ['info'] 
     _____          _
    / ____|        | |
   | |     ___   __| | ___  ___ _____   __
   | |    / _ \ / _` |/ _ \/ __/ _ \ \ / /
   | |___| (_) | (_| |  __/ (_| (_) \ V /
    \_____\___/ \__,_|\___|\___\___/ \_/
  Codecov report uploader 0.5.0
[2023-05-03T12:54:45.944Z] ['info'] => Project root located at: /opt/atlassian/pipelines/agent/build
[2023-05-03T12:54:45.949Z] ['info'] ->  Token found by environment variables
[2023-05-03T12:54:45.950Z] ['verbose'] Start of network processing...
[2023-05-03T12:54:45.950Z] ['verbose'] Searching for files in /opt/atlassian/pipelines/agent/build
[2023-05-03T12:54:45.998Z] ['verbose'] coveragepy is not installed
[2023-05-03T12:54:45.998Z] ['info'] Searching for coverage files...
[2023-05-03T12:54:46.158Z] ['info'] Warning: Some files located via search were excluded from upload.
[2023-05-03T12:54:46.158Z] ['info'] If Codecov did not locate your files, please review https://docs.codecov.com/docs/supported-report-formats
[2023-05-03T12:54:46.158Z] ['verbose'] Preparing to clean the following coverage paths: codecov.yaml,storage/coverage/coverage.xml
[2023-05-03T12:54:46.159Z] ['info'] => Found 2 possible coverage files:
  codecov.yaml
  storage/coverage/coverage.xml
[2023-05-03T12:54:46.159Z] ['verbose'] End of network processing
[2023-05-03T12:54:46.159Z] ['info'] Processing /opt/atlassian/pipelines/agent/build/codecov.yaml...
[2023-05-03T12:54:46.161Z] ['info'] Processing /opt/atlassian/pipelines/agent/build/storage/coverage/coverage.xml...
[2023-05-03T12:54:46.221Z] ['info'] Detected Bitbucket as the CI provider.
[2023-05-03T12:54:46.222Z] ['verbose'] -> Using the following env variables:
[2023-05-03T12:54:46.222Z] ['verbose']      CI: true
[2023-05-03T12:54:46.222Z] ['verbose']      BITBUCKET_BUILD_NUMBER: 360
[2023-05-03T12:54:46.228Z] ['verbose'] Using the following upload parameters:
[2023-05-03T12:54:46.228Z] ['verbose'] branch
[2023-05-03T12:54:46.228Z] ['verbose'] build
[2023-05-03T12:54:46.228Z] ['verbose'] buildURL
[2023-05-03T12:54:46.228Z] ['verbose'] commit
[2023-05-03T12:54:46.228Z] ['verbose'] job
[2023-05-03T12:54:46.228Z] ['verbose'] pr
[2023-05-03T12:54:46.228Z] ['verbose'] service
[2023-05-03T12:54:46.228Z] ['verbose'] slug
[2023-05-03T12:54:46.228Z] ['verbose'] name
[2023-05-03T12:54:46.228Z] ['verbose'] tag
[2023-05-03T12:54:46.228Z] ['verbose'] flags
[2023-05-03T12:54:46.228Z] ['verbose'] parent
[2023-05-03T12:54:46.229Z] ['info'] Pinging Codecov: https://codecov.io/upload/v4?package=uploader-0.5.0&token=*******&branch=pipeline-codecov-test-fix&build=360&build_url=&commit=&job=360&pr=91&service=bitbucket&slug=ware_com%2Fbackend-api&name=&tag=&flags=&parent=
[2023-05-03T12:54:46.230Z] ['verbose'] Passed token was 36 characters long
[2023-05-03T12:54:46.230Z] ['verbose'] https://codecov.io/upload/v4?package=uploader-0.5.0&branch=pipeline-codecov-test-fix&build=360&build_url=&commit=&job=360&pr=91&service=bitbucket&slug=ware_com%2Fbackend-api&name=&tag=&flags=&parent=
        Content-Type: 'text/plain'
        Content-Encoding: 'gzip'
        X-Reduced-Redundancy: 'false'
[2023-05-03T12:54:46.391Z] ['error'] There was an error running the uploader: Error uploading to https://codecov.io: Error: There was an error fetching the storage URL during POST: 400 - Invalid request parameters
[2023-05-03T12:54:46.392Z] ['verbose'] The error stack is: Error: Error uploading to https://codecov.io: Error: There was an error fetching the storage URL during POST: 400 - Invalid request parameters
    at main (/snapshot/repo/dist/src/index.js)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
[2023-05-03T12:54:46.392Z] ['verbose'] End of uploader: 457 milliseconds

Expected Results

Below is an output when the step is run in default pipeline

./codecov -t ${CODECOV_TOKEN} -f storage/coverage/coverage.xml
[2023-05-03T11:08:40.729Z] ['info'] 
     _____          _
    / ____|        | |
   | |     ___   __| | ___  ___ _____   __
   | |    / _ \ / _` |/ _ \/ __/ _ \ \ / /
   | |___| (_) | (_| |  __/ (_| (_) \ V /
    \_____\___/ \__,_|\___|\___\___/ \_/
  Codecov report uploader 0.5.0
[2023-05-03T11:08:40.735Z] ['info'] => Project root located at: /opt/atlassian/pipelines/agent/build
[2023-05-03T11:08:40.738Z] ['info'] ->  Token found by arguments
[2023-05-03T11:08:40.769Z] ['info'] Searching for coverage files...
[2023-05-03T11:08:40.875Z] ['info'] => Found 1 possible coverage files:
  storage/coverage/coverage.xml
[2023-05-03T11:08:40.875Z] ['info'] Processing /opt/atlassian/pipelines/agent/build/storage/coverage/coverage.xml...
[2023-05-03T11:08:40.946Z] ['info'] Detected Bitbucket as the CI provider.
[2023-05-03T11:08:40.947Z] ['info'] Pinging Codecov: https://codecov.io/upload/v4?package=uploader-0.5.0&token=*******&branch=testing&build=354&build_url=&commit=5bf00808e05e76f62dea181807ff6ef9590b9b2b&job=354&pr=&service=bitbucket&slug=ware_com%2Fbackend-api&name=&tag=&flags=&parent=
[2023-05-03T11:08:41.432Z] ['info'] https://app.codecov.io/bitbucket/****/backend-api/commit/5bf00808e05e76f62dea181807ff6ef9590b9b2b
https://storage.googleapis.com/codecov/v4/raw/2023-05-03/4D874282561FB89D9EA2575C05B7EFFA/5bf00808e05e76f62dea181807ff6ef9590b9b2b/9869ff1f-c4d3-4b8e-b264-d6a1e265f082.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=GOOG1EJOGFN2JQ4OCTGA2MU5AEIT7OT5Z7HTFOAN2SPG4NWSN2UJYOY5U6LZQ%2F20230503%2FUS%2Fs3%2Faws4_request&X-Amz-Date=20230503T110841Z&X-Amz-Expires=10&X-Amz-SignedHeaders=host&X-Amz-Signature=ae6cd8320b504cd75407bc407e29474f2aa756b512428cc4a31afed53ddff8b4
[2023-05-03T11:08:41.433Z] ['info'] Uploading...
[2023-05-03T11:08:41.608Z] ['info'] {"status":"success","resultURL":"https://app.codecov.io/bitbucket/****/backend-api/commit/5bf00808e05e76f62dea181807ff6ef9590b9b2b"}

Actual Results

See attached codecov results

Additional Information

Please provide applicable commit SHAs or file names that are extraneous or missing. Any additional information, configuration, or data that might be necessary to reproduce the issue.

Below is the bitbucket-pipeline.yml pipeline for a pull request (non-working pipeline)

pipelines:
  pull-requests:
     '**': 
      - step:
          name: Run Tests and Post to CodeCov
          script:
            - curl -Os https://uploader.codecov.io/latest/linux/codecov
            - chmod +x codecov
            - php -d memory_limit=-1 artisan test --coverage --coverage-clover storage/coverage/coverage.xml
            - ./codecov --verbose
          services:
            - docker

Below is the bitbucket-pipeline.yml for a default pipeline (working pipeline)

pipelines:
  default:
     - step:
          name: Run Tests and Post to CodeCov
          script:
            - curl -Os https://uploader.codecov.io/latest/linux/codecov
            - chmod +x codecov
            - php -d memory_limit=-1 artisan test --coverage --coverage-clover storage/coverage/coverage.xml
            - ./codecov --verbose
          services:
            - docker

@Bradley-Rock so I think the issue is maybe getting the commit value. This function is what we use to figure it out, so I’m suspecting that something is wrong with the CI side of things.

function _getSHA(inputs: UploaderInputs): string {
  const { args, environment: envs } = inputs
  let commit = envs.BITBUCKET_COMMIT || ''

  if (commit && validateSHA(commit, 12)) {
    commit = runExternalProgram('git', ['rev-parse', commit])
  }

  return args.sha || commit || ''
}

What I would like to know is if BITBUCKET_COMMIT is being set, and if so, what is the value for it.

That’s fixed it thank you. I was able to get it running via the argument “-C ${BITBUCKET_COMMIT}”

@Bradley-Rock just out of curiosity, did you mean BITBUCKET_COMMIT here?

1 Like