ci_exec.provider¶
Mechanisms to detect a given CI 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
-
class
ci_exec.provider.
ProviderMeta
[source]¶ Metaclass for
Provider
.This metaclass populates
Provider._all_provider_functions
by coordinating with theprovider()
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
If you are running on any CI service, or
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.
Whether or not the code is executing on AppVeyor.
Whether or not the code is executing on Azure Pipelines.
Whether or not the code is executing on CircleCI.
Whether or not the code is executing on Jenkins.
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.
Add a new
is_{new_provider}
method to this class, decorated with@provider
. Keep these alphabetically sorted (except foris_ci
, which should always be first).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.
Add to the
_specific_providers
list of environment variables in thetests/provider.py
file (nearprovider_sum()
).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, theProvider
class is not intended to be instantiated.- Type
-
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 ifany([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.
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.