Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

First steps for adding Azure Pipelines #194

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion codecov/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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
# --------
Expand Down
34 changes: 33 additions & 1 deletion tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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',
Expand Down