diff --git a/codecov/__init__.py b/codecov/__init__.py index 39d9a980..4db4c4b7 100644 --- a/codecov/__init__.py +++ b/codecov/__init__.py @@ -297,7 +297,7 @@ def main(*argv, **kwargs): # Travis CI # --------- elif os.getenv('CI') == 'true' and os.getenv('TRAVIS') == "true" and os.getenv('SHIPPABLE') != 'true': - # http://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables + # https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables query.update(dict(branch=os.getenv('TRAVIS_BRANCH'), service='travis', build=os.getenv('TRAVIS_JOB_NUMBER'), @@ -316,6 +316,27 @@ def main(*argv, **kwargs): if language: _add_env_if_not_empty(include_env, 'TRAVIS_%s_VERSION' % language.upper()) + # --------------- + # Azure Pipelines + # --------------- + elif os.getenv("TF_BUILD") == "True" and os.getenv("SHIPPABLE") != "true": + # https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml + # https://docs.microsoft.com/en-us/azure/devops/pipelines/migrate/from-travis?view=azure-devops#predefined-variables + query.update(dict(branch=os.getenv("BUILD_SOURCEBRANCH", + os.getenv("SYSTEM_PULLREQUEST_TARGETBRANCH")), + service="azure_pipelines", + build=os.getenv("AGENT_JOBNAME"), + pr=os.getenv("SYSTEM_PULLREQUEST_PULLREQUESTID", + os.getenv("SYSTEM_PULLREQUEST_PULLREQUESTNUMBER")), + tag=os.getenv("BUILD_SOURCEBRANCH"), + slug=os.getenv("BUILD_REPOSITORYNAME"), + commit=os.getenv("BUILD_SOURCEVERSION"), + ), + ) + root = os.getenv("BUILD_SOURCESDIRECTORY") or root + write(" Azure Pipelines Detected") + _add_env_if_not_empty(include_env, "AGENT_OS") + # -------- # Codeship # -------- diff --git a/tests/test.py b/tests/test.py index 5d3f23e2..23346fea 100644 --- a/tests/test.py +++ b/tests/test.py @@ -45,7 +45,13 @@ def setUp(self): "APPVEYOR_BUILD_VERSION", "APPVEYOR_JOB_ID", "APPVEYOR_REPO_NAME", "APPVEYOR_REPO_COMMIT", "WERCKER_GIT_BRANCH", "WERCKER_MAIN_PIPELINE_STARTED", "WERCKER_GIT_OWNER", "WERCKER_GIT_REPOSITORY", "CI_BUILD_REF_NAME", "CI_BUILD_ID", "CI_BUILD_REPO", "CI_PROJECT_DIR", "CI_BUILD_REF", "CI_SERVER_NAME", - "ghprbActualCommit", "ghprbSourceBranch", "ghprbPullId", "WERCKER_GIT_COMMIT", "CHANGE_ID"): + "ghprbActualCommit", "ghprbSourceBranch", "ghprbPullId", "WERCKER_GIT_COMMIT", "CHANGE_ID", + "AGENT_JOBNAME", "AGENT_OS", "BUILD_REPOSITORYNAME", + "BUILD_SOURCEBRANCH", "BUILD_SOURCESDIRECTORY", + "BUILD_SOURCEVERSION", "SYSTEM_PULLREQUEST_PULLREQUESTID", + "SYSTEM_PULLREQUEST_PULLREQUESTNUMBER", + "SYSTEM_PULLREQUEST_TARGETBRANCH", "TF_BUILD", + ): os.environ[key] = "" def tearDown(self): @@ -392,6 +398,32 @@ def test_ci_travis(self): self.assertEqual(res['query']['branch'], 'master') self.assertEqual(res['codecov'].token, '') + @unittest.skipUnless(os.getenv("TF_BUILD") == "true" + and os.getenv("SHIPPABLE") != "true", + "Skip Azure Pipelines test") + def test_ci_azurepipelines(self): + self.set_env(TF_BUILD="True", + AGENT_JOBNAME="job name", + AGENT_OS="Linux", + BUILD_REPOSITORYNAME="owner/repo", + BUILD_SOURCEBRANCH="feature-branch", + BUILD_SOURCESDIRECTORY="some/path", + BUILD_SOURCEVERSION="c739768fcac68144a3a6d82305b9c4106934d31a", + SYSTEM_PULLREQUEST_PULLREQUESTID="123", + SYSTEM_PULLREQUEST_PULLREQUESTNUMBER="123456", + SYSTEM_PULLREQUEST_TARGETBRANCH="master", + ) + self.fake_report() + res = self.run_cli() + self.assertEqual(res['query']['service'], 'azure_pipelines') + self.assertEqual(res['query']['commit'], 'c739768fcac68144a3a6d82305b9c4106934d31a') + self.assertEqual(res['query']['build'], 'job name') + self.assertEqual(res['query']['pr'], '123') + self.assertEqual(res['query']['tag'], 'feature-branch') + self.assertEqual(res['query']['slug'], 'owner/repo') + self.assertEqual(res['query']['branch'], 'feature-branch') + self.assertEqual(res['codecov'].token, '') + @unittest.skipUnless(os.getenv('CI') == 'true' and os.getenv('CI_NAME') == 'codeship', 'Skip Codeship CI test') def test_ci_codeship(self): self.set_env(CI_NAME='codeship',