Skip to content

Azure Pipelines adapter can send pullid: "", rejected by self-hosted Codecov #820

Backlog

Description

@renefritze

Summary

On a non-PR Azure Pipelines build, upload-coverage fails against a self-hosted
Codecov with:

Upload failed: {"pullid":["A valid integer is required."]}

The same upload succeeds against codecov.io.

Cause

AzurePipelinesCIAdapter._get_pull_request_number
(codecov_cli/helpers/ci_adapters/azure_pipelines.py) returns

os.getenv("SYSTEM_PULLREQUEST_PULLREQUESTNUMBER") or os.getenv("SYSTEM_PULLREQUEST_PULLREQUESTID")

When both variables are set but empty (as on our Windows agents for non-PR builds),
"" or "" evaluates to "", not None. CodecovOption.get_default
(codecov_cli/fallbacks.py) only skips a fallback when it is None, so "" is used.
upload_sender.py then sends "pullid": "".

Self-hosted UploadCoverageView passes request.data["pullid"] to CommitSerializer
(Commit.pullid = IntegerField(null=True)). DRF accepts null but rejects "".

Other adapters that return os.getenv(...) directly (Jenkins CHANGE_ID, GitLab
CI_MERGE_REQUEST_IID, CircleCI, Drone, Bitbucket, ...) have the same exposure.

Why codecov.io doesn't fail

Probing POST /upload/github/<slug>/upload-coverage with pullid set to "",
"None" and "abc":

Endpoint result
ingest.codecov.io 202 for all three, raw_upload_location under shelter/
self-hosted API 400 {"pullid":["A valid integer is required."]} for all three

So the hosted front end accepts any pullid; the open-source API validates it.
The client bug is hidden on codecov.io.

Reproduce

SYSTEM_TEAMFOUNDATIONCOLLECTIONURI=https://dev.azure.com/x/ \
SYSTEM_PULLREQUEST_PULLREQUESTNUMBER= SYSTEM_PULLREQUEST_PULLREQUESTID= \
codecovcli upload-coverage --url <self-hosted> ...

Suggested fix

Normalise empty values to None in the adapters, e.g. for Azure:

return (
    os.getenv("SYSTEM_PULLREQUEST_PULLREQUESTNUMBER")
    or os.getenv("SYSTEM_PULLREQUEST_PULLREQUESTID")
    or None
)

or, more generally, make CIAdapterBase.get_fallback_value return None for "".

Workaround

Unset both variables for the CLI process (env -u SYSTEM_PULLREQUEST_PULLREQUESTNUMBER -u SYSTEM_PULLREQUEST_PULLREQUESTID codecovcli ...), and don't pass
--pull-request-number unless the value is numeric.

Seen on codecov-cli 11.2.6 and 11.3.2.

Activity

  1. changed the title [-]Azure Pipelines adapter can send , rejected by self-hosted Codecov[/-] [+]Azure Pipelines adapter can send `pullid: ""`, rejected by self-hosted Codecov[/+] on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions