ci_exec.provider¶
Mechanisms to detect a given CI provider.
Provider()Check if code is executing on a continuous integration (CI) service.
- provider(func)[source]¶
Mark a function as a CI provider.
Not intended for use outside of the
Providerclass.- Parameters
func – The function to decorate.
- Returns
A static method that has an attribute
register_provider=True.- Return type
- class ProviderMeta(name, bases, attrs)[source]¶
Metaclass for
Provider.This metaclass populates
Provider._all_provider_functionsby coordinating with theprovider()decorator.Not intended to be used as a metaclass for any other classes.
- class 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 GitHub Actions.
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_providerslist of environment variables in thetests/provider.pyfile (nearprovider_sum()).Add a “pseudo-test” in
tests/provider.pyin 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, theProviderclass is not intended to be instantiated.- Type
- static is_ci()[source]¶
Whether or not the code is executing on a CI service.
Environment variables considered:
Environment Variable
Environment Value
CItrue(case insensitive)CONTINUOUS_INTEGRATIONtrue(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()[source]¶
Whether or not the code is executing on AppVeyor.
Environment variables considered:
Environment Variable
Environment Value
APPVEYORtrue(case insensitive)
- static is_azure_pipelines()[source]¶
Whether or not the code is executing on Azure Pipelines.
Environment variables considered:
Environment Variable
Environment Value
AZURE_HTTP_USER_AGENTExistence checked, value ignored.
AGENT_NAMEExistence checked, value ignored.
BUILD_REASONExistence checked, value ignored.
Note
All three must be set for this function to return
True.
- static is_circle_ci()[source]¶
Whether or not the code is executing on CircleCI.
Environment variables considered:
Environment Variable
Environment Value
CIRCLECItrue(case insensitive)
- static is_github_actions()[source]¶
Whether or not the code is executing on GitHub Actions.
Environment variables considered:
Environment Variable
Environment Value
GITHUB_ACTIONStrue(case insensitive)
- static is_jenkins()[source]¶
Whether or not the code is executing on Jenkins.
Environment variables considered:
Environment Variable
Environment Value
JENKINS_URLExistence checked, value ignored.
BUILD_NUMBERExistence checked, value ignored.
Note
Both must be set for this function to return
True.
- static is_travis()[source]¶
Whether or not the code is executing on Travis.
Environment variables considered:
Environment Variable
Environment Value
TRAVIStrue(case insensitive)
Tests¶
Tests for the ci_exec.provider module.
- test_provider_is_ci()[source]¶
Validate
Provider.is_ci()reports as expected.
- test_provider_is_appveyor()[source]¶
Validate
Provider.is_appveyor()reports as expected.
- test_provider_is_azure_pipelines()[source]¶
Validate
Provider.is_azure_pipelines()reports as expected.
- test_provider_is_circle_ci()[source]¶
Validate
Provider.is_circle_ci()reports as expected.
- test_provider_is_github_actions()[source]¶
Validate
Provider.is_github_actionsreports as expected.
- test_provider_is_jenkins()[source]¶
Validate
Provider.is_jenkins()reports as expected.
- test_provider_is_travis()[source]¶
Validate
Provider.is_travis()reports as expected.