@@ -47,6 +47,15 @@ public class BuildIntegrationTests : RepoTestBase, IClassFixture<MSBuildFixture>
4747
4848 public BuildIntegrationTests ( ITestOutputHelper logger )
4949 : base ( logger )
50+ {
51+ // MSBuildExtensions.LoadMSBuild will be called as part of the base constructor, because this class
52+ // implements the IClassFixture<MSBuildFixture> interface. LoadMSBuild will load the MSBuild assemblies.
53+ // This must happen _before_ any method that directly references types in the Microsoft.Build namespace has been called.
54+ // Net, don't init MSBuild-related fields in the constructor, but in a method that is called by the constructor.
55+ this . Init ( ) ;
56+ }
57+
58+ private void Init ( )
5059 {
5160 int seed = ( int ) DateTime . Now . Ticks ;
5261 this . random = new Random ( seed ) ;
@@ -651,6 +660,53 @@ public async Task BuildNumber_VariousOptions(bool isPublic, VersionOptions.Cloud
651660 this . AssertStandardProperties ( versionOptions , buildResult ) ;
652661 }
653662
663+ [ Fact ]
664+ public void GitLab_BuildTag ( )
665+ {
666+ // Based on the values defined in https://docs.gitlab.com/ee/ci/variables/#syntax-of-environment-variables-in-job-scripts
667+ using ( ApplyEnvironmentVariables (
668+ CloudBuild . SuppressEnvironment . SetItems (
669+ new Dictionary < string , string > ( )
670+ {
671+ { "CI_COMMIT_TAG" , "1.0.0" } ,
672+ { "CI_COMMIT_SHA" , "1ecfd275763eff1d6b4844ea3168962458c9f27a" } ,
673+ { "GITLAB_CI" , "true" } ,
674+ { "SYSTEM_TEAMPROJECTID" , string . Empty }
675+ } ) ) )
676+ {
677+ var activeCloudBuild = Nerdbank . GitVersioning . CloudBuild . Active ;
678+ Assert . NotNull ( activeCloudBuild ) ;
679+ Assert . Null ( activeCloudBuild . BuildingBranch ) ;
680+ Assert . Equal ( "refs/tags/1.0.0" , activeCloudBuild . BuildingTag ) ;
681+ Assert . Equal ( "1ecfd275763eff1d6b4844ea3168962458c9f27a" , activeCloudBuild . GitCommitId ) ;
682+ Assert . True ( activeCloudBuild . IsApplicable ) ;
683+ Assert . False ( activeCloudBuild . IsPullRequest ) ;
684+ }
685+ }
686+
687+ [ Fact ]
688+ public void GitLab_BuildBranch ( )
689+ {
690+ // Based on the values defined in https://docs.gitlab.com/ee/ci/variables/#syntax-of-environment-variables-in-job-scripts
691+ using ( ApplyEnvironmentVariables (
692+ CloudBuild . SuppressEnvironment . SetItems (
693+ new Dictionary < string , string > ( )
694+ {
695+ { "CI_COMMIT_REF_NAME" , "master" } ,
696+ { "CI_COMMIT_SHA" , "1ecfd275763eff1d6b4844ea3168962458c9f27a" } ,
697+ { "GITLAB_CI" , "true" } ,
698+ } ) ) )
699+ {
700+ var activeCloudBuild = Nerdbank . GitVersioning . CloudBuild . Active ;
701+ Assert . NotNull ( activeCloudBuild ) ;
702+ Assert . Equal ( "refs/heads/master" , activeCloudBuild . BuildingBranch ) ;
703+ Assert . Null ( activeCloudBuild . BuildingTag ) ;
704+ Assert . Equal ( "1ecfd275763eff1d6b4844ea3168962458c9f27a" , activeCloudBuild . GitCommitId ) ;
705+ Assert . True ( activeCloudBuild . IsApplicable ) ;
706+ Assert . False ( activeCloudBuild . IsPullRequest ) ;
707+ }
708+ }
709+
654710 [ Fact ]
655711 public async Task PublicRelease_RegEx_SatisfiedByCheckedOutBranch ( )
656712 {
0 commit comments