Skip to content

Commit

Permalink
feat(jenkins): add support for jenkins (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKevJames authored Aug 27, 2017
1 parent 7383f37 commit 4e8cd9e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 23 deletions.
11 changes: 9 additions & 2 deletions coveralls/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def load_config_from_circle():
pr = os.environ.get('CI_PULL_REQUEST', '').split('/')[-1] or None
return 'circle-ci', os.environ.get('CIRCLE_BUILD_NUM'), pr

@staticmethod
def load_config_from_jenkins():
return 'jenkins', os.environ.get('BUILD_NUMBER'), None

@staticmethod
def load_config_from_travis():
pr = os.environ.get('TRAVIS_PULL_REQUEST')
Expand All @@ -96,6 +100,8 @@ def load_config_from_ci_environment(self):
if os.environ.get('CIRCLECI'):
self._token_required = False
return self.load_config_from_circle()
if os.environ.get('JENKINS_HOME'):
return self.load_config_from_jenkins()
if os.environ.get('TRAVIS'):
self._token_required = False
return self.load_config_from_travis()
Expand Down Expand Up @@ -272,10 +278,11 @@ def git_info():
'committer_email': gitlog('%ce'),
'message': gitlog('%s'),
},
'branch': (os.environ.get('CIRCLE_BRANCH') or
os.environ.get('APPVEYOR_REPO_BRANCH') or
'branch': (os.environ.get('APPVEYOR_REPO_BRANCH') or
os.environ.get('BUILDKITE_BRANCH') or
os.environ.get('CI_BRANCH') or
os.environ.get('CIRCLE_BRANCH') or
os.environ.get('GIT_BRANCH') or
os.environ.get('TRAVIS_BRANCH', rev)),
'remotes': [{'name': line.split()[0], 'url': line.split()[1]}
for line in remotes if '(fetch)' in line]
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/configuration.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Configuration
=============

coveralls-python often works without any outside configuration by examining the environment it is being run in. Special handling has been added for AppVeyor, BuildKite, CircleCI, and TravisCI to make coveralls-python as close to "plug and play" as possible.
coveralls-python often works without any outside configuration by examining the environment it is being run in. Special handling has been added for AppVeyor, BuildKite, CircleCI, Jenkins, and TravisCI to make coveralls-python as close to "plug and play" as possible.

Most often, you will simply need to run coveralls-python with no additional options after you have run your coverage suite::

Expand Down
6 changes: 6 additions & 0 deletions docs/usage/tox.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ CircleCI

passenv = CIRCLECI CIRCLE_BUILD_NUM CIRCLE_BRANCH CI_PULL_REQUEST

Jenkins
-------
::

passenv = JENKINS_HOME BUILD_NUMBER GIT_BRANCH

TravisCI
--------
::
Expand Down
47 changes: 27 additions & 20 deletions tests/api/configuration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ def test_local_with_config_without_yaml_module(self, mock_logger):

@mock.patch.object(Coveralls, 'config_filename', '.coveralls.mock')
class NoConfiguration(unittest.TestCase):
@mock.patch.dict(os.environ, {'TRAVIS': 'True',
'TRAVIS_JOB_ID': '777'}, clear=True)
def test_travis_no_config(self):
cover = Coveralls()
assert cover.config['service_name'] == 'travis-ci'
assert cover.config['service_job_id'] == '777'
assert 'repo_token' not in cover.config

@mock.patch.dict(os.environ, {'TRAVIS': 'True',
'TRAVIS_JOB_ID': '777',
'COVERALLS_REPO_TOKEN': 'yyy'}, clear=True)
Expand All @@ -70,18 +62,6 @@ def test_misconfigured(self):
'Not on Travis or CircleCI. You have to provide either repo_token '
'in .coveralls.mock or set the COVERALLS_REPO_TOKEN env var.')

@mock.patch.dict(
os.environ,
{'CIRCLECI': 'True',
'CIRCLE_BUILD_NUM': '888',
'CI_PULL_REQUEST': 'https://github.com/org/repo/pull/9999'},
clear=True)
def test_circleci_no_config(self):
cover = Coveralls()
assert cover.config['service_name'] == 'circle-ci'
assert cover.config['service_job_id'] == '888'
assert cover.config['service_pull_request'] == '9999'

@mock.patch.dict(os.environ, {'APPVEYOR': 'True',
'APPVEYOR_BUILD_ID': '1234567',
'APPVEYOR_PULL_REQUEST_NUMBER': '1234'},
Expand All @@ -98,3 +78,30 @@ def test_buildkite_no_config(self):
cover = Coveralls(repo_token='xxx')
assert cover.config['service_name'] == 'buildkite'
assert cover.config['service_job_id'] == '1234567'

@mock.patch.dict(
os.environ,
{'CIRCLECI': 'True',
'CIRCLE_BUILD_NUM': '888',
'CI_PULL_REQUEST': 'https://github.com/org/repo/pull/9999'},
clear=True)
def test_circleci_no_config(self):
cover = Coveralls()
assert cover.config['service_name'] == 'circle-ci'
assert cover.config['service_job_id'] == '888'
assert cover.config['service_pull_request'] == '9999'

@mock.patch.dict(os.environ, {'JENKINS_HOME': '/var/lib/jenkins',
'BUILD_NUMBER': '888'}, clear=True)
def test_jenkins_no_config(self):
cover = Coveralls(repo_token='xxx')
assert cover.config['service_name'] == 'jenkins'
assert cover.config['service_job_id'] == '888'

@mock.patch.dict(os.environ, {'TRAVIS': 'True',
'TRAVIS_JOB_ID': '777'}, clear=True)
def test_travis_no_config(self):
cover = Coveralls()
assert cover.config['service_name'] == 'travis-ci'
assert cover.config['service_job_id'] == '777'
assert 'repo_token' not in cover.config

0 comments on commit 4e8cd9e

Please sign in to comment.