Skip to content

Commit

Permalink
Merge pull request #4419 from ap0llo/4418-add-server-url-to-gitlabcis…
Browse files Browse the repository at this point in the history
…erverinfo

Add Url property to GitLabCIServerInfo (#4418)
  • Loading branch information
devlead authored Jan 4, 2025
2 parents caced43 + a834a59 commit ec19bf9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public GitLabCIInfoFixture(bool versionNineOrNewer = false)
Environment.GetEnvironmentVariable("CI_RUNNER_DESCRIPTION").Returns("my runner");
Environment.GetEnvironmentVariable("CI_RUNNER_TAGS").Returns("[\"docker\", \"linux\"]");
Environment.GetEnvironmentVariable("CI_SERVER").Returns("yes");
Environment.GetEnvironmentVariable("CI_SERVER_URL").Returns("https://gitlab.example.com:8080");
Environment.GetEnvironmentVariable("CI_SERVER_NAME").Returns("GitLab");
Environment.GetEnvironmentVariable("CI_SERVER_REVISION").Returns("70606bf");
Environment.GetEnvironmentVariable("CI_SERVER_VERSION").Returns("8.9.0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,20 @@ public void Should_Return_Correct_Value()
Assert.Equal("8.9.0", result);
}
}
}

public sealed class TheUrlProperty
{
[Fact]
public void Should_Return_Correct_Value()
{
// Given
var info = new GitLabCIInfoFixture().CreateServerInfo();

// When
var result = info.Url;

// Then
Assert.Equal("https://gitlab.example.com:8080", result);
}
}
}
8 changes: 8 additions & 0 deletions src/Cake.Common/Build/GitLabCI/Data/GitLabCIServerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,13 @@ public GitLabCIServerInfo(ICakeEnvironment environment)
/// The GitLab revision that is used to schedule builds.
/// </value>
public string Revision => GetEnvironmentString("CI_SERVER_REVISION");

/// <summary>
/// Gets the base URL of the GitLab instance, including protocol and port.
/// </summary>
/// <value>
/// The base URL of the GitLab instance, including protocol and port.
/// </value>
public string Url => GetEnvironmentString("CI_SERVER_URL");
}
}

0 comments on commit ec19bf9

Please sign in to comment.