Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add Bitbucket Cloud provider
  • Loading branch information
LoremFooBar committed Jul 27, 2022
commit 063c3b50f4568b3213553b04f1cbbb1c3fd13fa2
5 changes: 5 additions & 0 deletions src/Cake.GitVersioning/GitVersioningCloudProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,10 @@ public enum GitVersioningCloudProvider
/// Use the Jetbrains Space cloud build provider.
/// </summary>
SpaceAutomation,

/// <summary>
/// Use the Bitbucket cloud build provider
/// </summary>
BitbucketCloud,
}
}
1 change: 1 addition & 0 deletions src/NerdBank.GitVersioning/CloudBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static class CloudBuild
new GitLab(),
new Travis(),
new SpaceAutomation(),
new BitbucketCloud(),
};

/// <summary>
Expand Down
37 changes: 37 additions & 0 deletions src/NerdBank.GitVersioning/CloudBuildServices/BitbucketCloud.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace Nerdbank.GitVersioning.CloudBuildServices;

/// <summary>
/// Cloud build handling for Bitbucket Cloud.
/// </summary>
/// <remarks>
/// The Bitbucket-specific properties referenced here are <see href="https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/">documented here</see>.
/// </remarks>
public class BitbucketCloud : ICloudBuild
{
/// <inheritdoc />
public bool IsApplicable => !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("BITBUCKET_REPO_SLUG"));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a risk of a false positive, if BITBUCKET_REPO_SLUG is defined by a Jenkins pipeline using Bitbucket Server, for example. Because Atlassian uses the "repository slug" term in REST API documentation, a pipeline author might use that name. Some other variable from https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/ might have a lower risk of such a conflict. BITBUCKET_PIPELINE_UUID looks most suitable, as Bitbucket Data Center and Server don't have pipelines, and Jenkins pipelines don't have UUIDs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point. If we really want to be on the safe side, I could test for multiple environment variables that are not commonly used:
BITBUCKET_PIPELINE_UUID
BITBUCKET_STEP_UUID
BITBUCKET_STEP_TRIGGERER_UUID

The chance of anyone defining all of these variables outside of an actual Bitbucket Pipelines environment is incredibly low.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for calling out this risk, @KalleOlaviNiemitalo


/// <inheritdoc />
public bool IsPullRequest => !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("BITBUCKET_PR_ID"));

/// <inheritdoc />
public string BuildingBranch => Environment.GetEnvironmentVariable("BITBUCKET_BRANCH");

/// <inheritdoc />
public string BuildingTag => Environment.GetEnvironmentVariable("BITBUCKET_TAG");

/// <inheritdoc />
public string GitCommitId => Environment.GetEnvironmentVariable("BITBUCKET_COMMIT");

/// <inheritdoc />
public IReadOnlyDictionary<string, string> SetCloudBuildNumber(string buildNumber, TextWriter stdout, TextWriter stderr)
{
return new Dictionary<string, string>();
}

/// <inheritdoc />
public IReadOnlyDictionary<string, string> SetCloudBuildVariable(string name, string value, TextWriter stdout, TextWriter stderr)
{
return new Dictionary<string, string>();
}
}