Skip to content
Merged
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
enhance GetCurrentBranch for drone
  • Loading branch information
Vadim Hatsura committed May 21, 2019
commit 4cf6d32871056bdb51461288e180230d18f5f2ef
25 changes: 25 additions & 0 deletions src/GitVersionCore/BuildServers/Drone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,31 @@ public override string[] GenerateSetParameterMessage(string name, string value)

public override string GetCurrentBranch(bool usingDynamicRepos)
{
// In Drone DRONE_BRANCH variable is equal to destination branch in case of pull request
// https://discourse.drone.io/t/getting-the-branch-a-pull-request-is-created-from/670
// Unfortunately, DRONE_REFSPEC isn't populated, however CI_COMMIT_REFSPEC can be used instead of.
var pullRequestNumber = Environment.GetEnvironmentVariable("DRONE_PULL_REQUEST");
if (!string.IsNullOrWhiteSpace(pullRequestNumber))
{
// DRONE_SOURCE_BRANCH is available in Drone 1.x.x version
var sourceBranch = Environment.GetEnvironmentVariable("DRONE_SOURCE_BRANCH");
if (!string.IsNullOrWhiteSpace(sourceBranch))
return sourceBranch;

// In drone lower than 1.x.x source branch can be parsed from CI_COMMIT_REFSPEC
// CI_COMMIT_REFSPEC - {sourceBranch}:{destinationBranch}
// https://github.com/drone/drone/issues/2222
var ciCommitRefSpec = Environment.GetEnvironmentVariable("CI_COMMIT_REFSPEC");
if (!string.IsNullOrWhiteSpace(ciCommitRefSpec))
{
var colonIndex = ciCommitRefSpec.IndexOf(':');
if (colonIndex > 0)
{
return ciCommitRefSpec.Substring(0, colonIndex);
}
}
}

return Environment.GetEnvironmentVariable("DRONE_BRANCH");
}
}
Expand Down