ci_exec.provider

Mechanisms to detect a given CI provider.

Provider

Check if code is executing on a continuous integration (CI) service.

ci_exec.provider.provider(func) → staticmethod[source]

Mark a function as a CI provider.

Not intended for use outside of the Provider class.

Parameters

func – The function to decorate.

Returns

A static method that has an attribute register_provider=True.

Return type

staticmethod()

class ci_exec.provider.ProviderMeta[source]

Metaclass for Provider.

This metaclass populates Provider._all_provider_functions by coordinating with the provider() decorator.

Not intended to be used as a metaclass for any other classes.

class ci_exec.provider.Provider[source]

Check if code is executing on a continuous integration (CI) service.

Every now and then it is useful to know

  1. If you are running on any CI service, or

  2. If you are running on a specific CI service.

The static methods in this class provide a way of checking for pre-defined (by the CI service provider) environment variables:

from ci_exec import Provider, which

def build():
    # ... run cmake etc ...
    ninja = which("ninja")
    if Provider.is_travis():
        # Ninja uses too much memory during link phase.  See:
        # "My build script is killed without any error"
        # https://docs.travis-ci.com/user/common-build-problems/
        ninja("-j", "2", "install")
    else:
        ninja("install")

Available Providers:

is_ci()

Whether or not the code is executing on a CI service.

is_appveyor()

Whether or not the code is executing on AppVeyor.

is_azure_pipelines()

Whether or not the code is executing on Azure Pipelines.

is_circle_ci()

Whether or not the code is executing on CircleCI.

is_jenkins()

Whether or not the code is executing on Jenkins.

is_travis()

Whether or not the code is executing on Travis.

Adding a New Provider:

Pull requests are welcome. Alternatively, simply raise an issue with a link to the provider’s main homepage as well as a link to the documentation certifying the environment variables we can rely on.

  1. Add a new is_{new_provider} method to this class, decorated with @provider. Keep these alphabetically sorted (except for is_ci, which should always be first).

  2. Document any environment variable(s) involved in a table, including hyperlinks to the provider’s main homepage as well as documentation describing the environment variables in question.

  3. Add to the _specific_providers list of environment variables in the tests/provider.py file (near provider_sum()).

  4. Add a “pseudo-test” in tests/provider.py in the appropriate location.

_all_provider_functions

Not intended for external usage. The list of all known (implemented) CI provider functions in this class. For example, it will contain Provider.is_appveyor(), …, Provider.is_travis(), etc. This is a class attribute, the Provider class is not intended to be instantiated.

Type

list

static is_ci() → bool[source]

Whether or not the code is executing on a CI service.

Environment variables considered:

Environment Variable

Environment Value

CI

true (case insensitive)

CONTINUOUS_INTEGRATION

true (case insensitive)

If neither of these are true, this function will query every provider directly. For example, it will end up checking if any([Provider.is_appveyor(), ..., Provider.is_travis(), ...]).

static is_appveyor() → bool[source]

Whether or not the code is executing on AppVeyor.

Environment variables considered:

Environment Variable

Environment Value

APPVEYOR

true (case insensitive)

static is_azure_pipelines() → bool[source]

Whether or not the code is executing on Azure Pipelines.

Environment variables considered:

Environment Variable

Environment Value

AZURE_HTTP_USER_AGENT

Existence checked, value ignored.

AGENT_NAME

Existence checked, value ignored.

BUILD_REASON

Existence checked, value ignored.

Note

All three must be set for this function to return True.

static is_circle_ci() → bool[source]

Whether or not the code is executing on CircleCI.

Environment variables considered:

Environment Variable

Environment Value

CIRCLECI

true (case insensitive)

static is_jenkins() → bool[source]

Whether or not the code is executing on Jenkins.

Environment variables considered:

Environment Variable

Environment Value

JENKINS_URL

Existence checked, value ignored.

BUILD_NUMBER

Existence checked, value ignored.

Note

Both must be set for this function to return True.

static is_travis() → bool[source]

Whether or not the code is executing on Travis.

Environment variables considered:

Environment Variable

Environment Value

TRAVIS

true (case insensitive)

Tests

Tests for the ci_exec.provider module.

tests.provider.provider_sum()[source]

Return number of Provider’s that return True.

tests.provider.test_provider_is_ci()[source]

Validate Provider.is_ci() reports as expected.

tests.provider.test_provider_is_appveyor()[source]

Validate Provider.is_appveyor() reports as expected.

tests.provider.test_provider_is_azure_pipelines()[source]

Validate Provider.is_azure_pipelines() reports as expected.

tests.provider.test_provider_is_circle_ci()[source]

Validate Provider.is_circle_ci() reports as expected.

tests.provider.test_provider_is_jenkins()[source]

Validate Provider.is_jenkins() reports as expected.

tests.provider.test_provider_is_travis()[source]

Validate Provider.is_travis() reports as expected.