From f6b1d90ef4b3eaccfb2c077080671cf430511779 Mon Sep 17 00:00:00 2001 From: Wojciech Dziemianczyk Date: Thu, 18 Mar 2021 10:46:08 -0400 Subject: [PATCH] Add Bitrise CI support (#45) * Add Bitrise CI support * Add docs for Bitrise --- README.md | 5 +++++ src/main/kotlin/ServiceInfoParser.kt | 9 ++++++++- src/test/kotlin/ServiceInfoParserTest.kt | 24 ++++++++++++++++++++++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ed598b2..b4ecdc9 100644 --- a/README.md +++ b/README.md @@ -305,6 +305,7 @@ The plugin can be used with the following CI providers: * Codeship * Buildkite * Gitlab CI +* Bitrise ### Travis @@ -363,3 +364,7 @@ See Buildkite environment variables [documentation](https://buildkite.com/docs/p ### Gitlab CI See Gitlab CI predefined variables [documentation](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html) + +### Bitrise CI + +See Bitrise CI predefined variables [documentation](https://devcenter.bitrise.io/builds/available-environment-variables/) \ No newline at end of file diff --git a/src/main/kotlin/ServiceInfoParser.kt b/src/main/kotlin/ServiceInfoParser.kt index f63e7e5..37ef9a3 100644 --- a/src/main/kotlin/ServiceInfoParser.kt +++ b/src/main/kotlin/ServiceInfoParser.kt @@ -20,6 +20,7 @@ class ServiceInfoParser(val envGetter: EnvGetter) { private val isGithubActionsToken = envGetter("GITHUB_TOKEN") != null private val isBuildkite = envGetter("BUILDKITE") == "true" private val isGitlab = envGetter("GITLAB_CI") != null + private val isBitrise = envGetter("BITRISE_IO") == "true" fun parse(): ServiceInfo { return when { @@ -86,7 +87,13 @@ class ServiceInfoParser(val envGetter: EnvGetter) { branch = envGetter("CI_COMMIT_BRANCH"), buildUrl = envGetter("CI_PIPELINE_URL") ) - + isBitrise -> ServiceInfo( + name = "bitrise", + number = envGetter("BITRISE_BUILD_NUMBER"), + pr = envGetter("BITRISE_PULL_REQUEST"), + branch = envGetter("BITRISE_GIT_BRANCH"), + buildUrl = envGetter("BITRISE_BUILD_URL") + ) else -> ServiceInfo("other") } } diff --git a/src/test/kotlin/ServiceInfoParserTest.kt b/src/test/kotlin/ServiceInfoParserTest.kt index 9ecb5a6..27d64e7 100644 --- a/src/test/kotlin/ServiceInfoParserTest.kt +++ b/src/test/kotlin/ServiceInfoParserTest.kt @@ -195,14 +195,34 @@ internal class ServiceInfoParserTest { val envGetter = createEnvGetter(mapOf( "GITLAB_CI" to "true", "CI_PIPELINE_ID" to "12341234", - "CI_PIPELINE_URL" to "https://gitlab.com.com/your-group/your-repo/pipelines/123", + "CI_PIPELINE_URL" to "https://gitlab.com/your-group/your-repo/pipelines/123", "CI_JOB_ID" to "43214321", "CI_COMMIT_BRANCH" to "foobar", "CI_MERGE_REQUEST_IID" to "11" )) val actual = ServiceInfoParser(envGetter).parse() - val expected = ServiceInfo(name = "gitlab-ci", number = "12341234", jobId = "43214321", pr = "11", branch = "foobar", buildUrl = "https://gitlab.com.com/your-group/your-repo/pipelines/123") + val expected = ServiceInfo(name = "gitlab-ci", number = "12341234", jobId = "43214321", pr = "11", branch = "foobar", buildUrl = "https://gitlab.com/your-group/your-repo/pipelines/123") + assertEquals(expected, actual) + } + + @Test + fun `ServiceInfoParser parses bitrise env`() { + val envGetter = createEnvGetter(mapOf( + "BITRISE_IO" to "true", + "BITRISE_BUILD_NUMBER" to "123123", + "BITRISE_PULL_REQUEST" to "11", + "BITRISE_GIT_BRANCH" to "foobar", + "BITRISE_BUILD_URL" to "https://app.bitrise.io/build/d75abbebxfc9ca4e" + )) + val actual = ServiceInfoParser(envGetter).parse() + val expected = ServiceInfo( + name = "bitrise", + number = "123123", + pr = "11", + branch = "foobar", + buildUrl = "https://app.bitrise.io/build/d75abbebxfc9ca4e" + ) assertEquals(expected, actual) }