Codecov CLI

The Codecov CLI represents a new way of interacting with Codecov directly in their terminals. Although it allows users to upload coverage reports to Codecov, it provides far more functionality than can be given from the universal uploader. Many of Codecov’s current and future features will be available through the Codecov CLI.

Installing the Codecov CLI

curl -Os https://cli.codecov.io/latest/linux/codecov  # for Mac users, replace `linux` with `macos`
chmod +x ./codecov

Using the Codecov CLI

After installing the Codecov CLI, you can use the CLI to upload coverage reports to Codecov, view coverage results, and more. For more information on each command, see Codecov CLI

Uploading coverage to Codecov

To upload coverage to Codecov, run the following

./codecov create-commit -t [CODECOV_TOKEN] --git-service github # or applicable service
./codecov create-report -t [CODECOV_TOKEN]
./codecov do-upload -t [CODECOV_TOKEN]

View coverage results locally

Note that [TEXT] must be replaced with the same string.

./codecov create-commit
./codecov create-report --code [TEXT]
./codecov do-upload --report-code [TEXT]
./codecov create-report-results --code [TEXT]
./codecov get-report-results --code [TEXT]

Codecov CLI commands

create-commit

Send the basic commit information to Codecov and instantiate the commit in the database.

  -C, --sha, --commit-sha TEXT    Commit SHA (with 40 chars)
  --parent-sha TEXT               SHA (with 40 chars) of what should be the
                                  parent of this commit
  -P, --pr, --pull-request-number TEXT
                                  Specify the pull request number mannually.
                                  Used to override pre-existing CI environment
                                  variables
  -B, --branch TEXT               Branch to which this commit belongs to
  -r, --slug TEXT                 owner/repo slug used instead of the private
                                  repo token in Self-hosted
  -t, --token UUID                [required] Codecov upload token
  --git-service                   [github|gitlab|bitbucket|github_enterprise|gitlab_enterprise|bitbucket_server]
  --help                          Show this message and exit.

create-report

Set up the scaffolding for a report for a given commit

  -C, --sha, --commit-sha TEXT    Commit SHA (with 40 chars)  [required]
  --code TEXT                     The code of the report. If unsure, leave
                                  default
  -r, --slug TEXT                 owner/repo slug used instead of the private
                                  repo token in Self-hosted
  --git-service [github|gitlab|bitbucket|github_enterprise|gitlab_enterprise|bitbucket_server]
  -t, --token UUID                Codecov upload token
  --help                          Show this message and exit.

create-report-results

Create the coverage report results for the user

  --commit-sha TEXT               Commit SHA (with 40 chars)  [required]
  --code TEXT                     The code of the report. If unsure, leave
                                  default
  --slug TEXT                     owner/repo slug used instead of the private
                                  repo token in Self-hosted  [required]
  --git-service [github|gitlab|bitbucket|github_enterprise|gitlab_enterprise|bitbucket_server]
  -t, --token UUID                Codecov upload token
  --help                          Show this message and exit.

do-upload

Upload coverage reports to Codecov.

  -C, --sha, --commit-sha TEXT    Commit SHA (with 40 chars)  [required]
  --report-code TEXT              The code of the report. If unsure, leave
                                  default
  --network-root-folder PATH      Root folder from which to consider paths on
                                  the network section  [default: (Current
                                  working directory)]
  -s, --dir, --coverage-files-search-root-folder PATH
                                  Folder where to search for coverage files
                                  [default: (Current Working Directory)]
  --exclude, --coverage-files-search-exclude-folder PATH
                                  Folders where to search for coverage files
  -f, --file, --coverage-files-search-direct-file PATH
                                  Explicit files to upload
  -b, --build, --build-code TEXT  Specify the build number manually
  --build-url TEXT                The URL of the build where this is running
  --job-code TEXT
  -t, --token UUID                Codecov upload token
  -n, --name TEXT                 Custom defined name of the upload. Visible
                                  in Codecov UI
  -B, --branch TEXT               Branch to which this commit belongs to
  -r, --slug TEXT                 owner/repo slug used instead of the private
                                  repo token in Self-hosted
  -P, --pr, --pull-request-number TEXT
                                  Specify the pull request number mannually.
                                  Used to override pre-existing CI environment
                                  variables
  -e, --env, --env-var TEXT       Specify environment variables to be included
                                  with this build.
  -F, --flag TEXT                 Flag the upload to group coverage metrics.
                                  Multiple flags allowed.
  --plugin TEXT
  -Z, --fail-on-error             Exit with non-zero code in case of error
                                  uploading.
  -d, --dry-run                   Don't upload files to Codecov
  --legacy, --use-legacy-uploader
                                  Use the legacy upload endpoint
  --git-service [github|gitlab|bitbucket|github_enterprise|gitlab_enterprise|bitbucket_server]
  --help                          Show this message and exit.

get-report-results

Retrieve the results of an uploaded coverage report

  --commit-sha TEXT               Commit SHA (with 40 chars)  [required]
  --code TEXT                     The code of the report. If unsure, leave
                                  default
  --slug TEXT                     owner/repo slug used instead of the private
                                  repo token in Self-hosted  [required]
  --git-service [github|gitlab|bitbucket|github_enterprise|gitlab_enterprise|bitbucket_server]
  -t, --token UUID                Codecov upload token
  --help                          Show this message and exit.

label-analysis

Send code analysis information to Codecov comparing two commits

  --token TEXT     [required]
  --head-sha TEXT  Commit SHA (with 40 chars)  [required]
  --base-sha TEXT  Commit SHA (with 40 chars)  [required]
  --help           Show this message and exit.

pr-base-picking

Set the base commit SHA of a given PR

  --base-sha TEXT   Base commit SHA (with 40 chars)  [required]
  --pr TEXT         Pull Request id to associate commit with
  --slug TEXT       owner/repo slug
  -t, --token UUID  Codecov upload token
  --service TEXT    Specify the service provider of the repo e.g. github
  --help            Show this message and exit.

static-analysis

Produces static analysis information on a commit to be used by Codecov

  --foldertosearch PATH      Folder to search
  --numberprocesses INTEGER  number of processes to use
  --pattern TEXT             file pattern to search for
  --force / --no-force
  --commit-sha TEXT          Commit SHA (with 40 chars)  [required]
  --token TEXT
  --help                     Show this message and exit.