/// <summary> /// Tags the build when running on Appveyor or AzureDevOps (GitLab does not support this). /// Note that if <see cref="ShouldStop"/> is true, " (Skipped)" is appended. /// </summary> /// <returns>This info object (allowing fluent syntax).</returns> public StandardGlobalInfo SetCIBuildTag() { string AddSkipped(string s) => ShouldStop ? s + " (Skipped)" : s; void AzurePipelineUpdateBuildVersion(SimpleRepositoryInfo gitInfo) { // Azure (formerly VSTS, formerly VSO) analyzes the stdout to set its build number. // On clash, the default Azure/VSTS/VSO build number is used: to ensure that the actual // version will be always be available we need to inject a uniquifier. string buildVersion = AddSkipped($"{gitInfo.SafeVersion}_{DateTime.UtcNow:yyyyMMdd-HHmmss}"); Cake.Information($"Using VSTS build number: {buildVersion}"); string buildInstruction = $"##vso[build.updatebuildnumber]{buildVersion}"; Console.WriteLine(); Console.WriteLine(buildInstruction); Console.WriteLine(); } void AppVeyorUpdateBuildVersion(IAppVeyorProvider appVeyor, SimpleRepositoryInfo gitInfo) { try { appVeyor.UpdateBuildVersion(AddSkipped(gitInfo.SafeVersion)); } catch { appVeyor.UpdateBuildVersion(AddSkipped($"{gitInfo.SafeVersion} ({appVeyor.Environment.Build.Number})")); } } var gitlab = Cake.GitLabCI(); if (gitlab.IsRunningOnGitLabCI) { // damned, we can't tag the pipeline/job. } else { IAppVeyorProvider appVeyor = Cake.AppVeyor(); if (appVeyor.IsRunningOnAppVeyor) { AppVeyorUpdateBuildVersion(appVeyor, _gitInfo); } else { ITFBuildProvider vsts = Cake.TFBuild(); if (vsts.IsRunningOnAzurePipelinesHosted || vsts.IsRunningOnAzurePipelines) { AzurePipelineUpdateBuildVersion(_gitInfo); } } } return(this); }
public void Setup() { _environment = FakeEnvironment.CreateWindowsEnvironment(); _log = new FakeLog(); _arguments = Substitute.For <ICakeArguments>(); _appVeyor = Substitute.For <IAppVeyorProvider>(); _azure = Substitute.For <ITFBuildProvider>(); _appEnvironment = new AppVeyorEnvironmentInfo(_environment); _appVeyor.Environment.Returns(_appEnvironment); _globber = Substitute.For <IGlobber>(); _fileSystem = new FakeFileSystem(_environment); _processRunner = Substitute.For <IProcessRunner>(); _toolLocator = Substitute.For <IToolLocator>(); }
/// <summary> /// Tags the build when running on Appveyor or AzureDevOps (GitLab does not support this). /// Note that if <see cref="ShouldStop"/> is true, " (Skipped)" is appended. /// </summary> /// <returns>This info object (allowing fluent syntax).</returns> public StandardGlobalInfo SetCIBuildTag() { string AddSkipped(string s) => ShouldStop ? s + " (Skipped)" : s; string ComputeAzurePipelineUpdateBuildVersion(SimpleRepositoryInfo gitInfo) { // Azure (formerly VSTS, formerly VSO) analyzes the stdout to set its build number. // On clash, the default Azure/VSTS/VSO build number is used: to ensure that the actual // version will be always be available we need to inject a uniquifier. string buildVersion = AddSkipped($"{gitInfo.SafeVersion}_{DateTime.UtcNow:yyyyMMdd-HHmmss}"); Cake.Information($"Using VSTS build number: {buildVersion}"); return($"##vso[build.updatebuildnumber]{buildVersion}"); } void AzurePipelineUpdateBuildVersion(string buildInstruction) { Console.WriteLine(); Console.WriteLine(buildInstruction); Console.WriteLine(); } IAppVeyorProvider appVeyor = Cake.AppVeyor(); ITFBuildProvider vsts = Cake.TFBuild(); try { string azureVersion = ComputeAzurePipelineUpdateBuildVersion(_gitInfo); string appveyorVersion = AddSkipped(_gitInfo.SafeVersion); if (appVeyor.IsRunningOnAppVeyor) //Warning: { appVeyor.UpdateBuildVersion(appveyorVersion); } if (vsts.IsRunningOnAzurePipelinesHosted || vsts.IsRunningOnAzurePipelines) { AzurePipelineUpdateBuildVersion(azureVersion); } } catch (Exception e) { Cake.Warning("Could not set the Build Version !!!"); Cake.Warning(e); } return(this); }
/// <summary> /// Initializes a new instance of the <see cref="BuildSystem" /> class. /// </summary> /// <param name="appVeyorProvider">The AppVeyor Provider.</param> /// <param name="teamCityProvider">The TeamCity Provider.</param> /// <param name="myGetProvider">The MyGet Provider.</param> /// <param name="bambooProvider">The Bamboo Provider.</param> /// <param name="continuaCIProvider">The Continua CI Provider.</param> /// <param name="jenkinsProvider">The Jenkins Provider.</param> /// <param name="bitriseProvider">The Bitrise Provider.</param> /// <param name="travisCIProvider">The Travis CI provider.</param> /// <param name="bitbucketPipelinesProvider">The Bitbucket Pipelines provider.</param> /// <param name="goCDProvider">The Go.CD provider.</param> /// <param name="gitlabCIProvider">The GitLab CI provider.</param> /// <param name="tfBuildProvider">The TF Build provider.</param> public BuildSystem( IAppVeyorProvider appVeyorProvider, ITeamCityProvider teamCityProvider, IMyGetProvider myGetProvider, IBambooProvider bambooProvider, IContinuaCIProvider continuaCIProvider, IJenkinsProvider jenkinsProvider, IBitriseProvider bitriseProvider, ITravisCIProvider travisCIProvider, IBitbucketPipelinesProvider bitbucketPipelinesProvider, IGoCDProvider goCDProvider, IGitLabCIProvider gitlabCIProvider, ITFBuildProvider tfBuildProvider) { if (appVeyorProvider == null) { throw new ArgumentNullException(nameof(appVeyorProvider)); } if (teamCityProvider == null) { throw new ArgumentNullException(nameof(teamCityProvider)); } if (myGetProvider == null) { throw new ArgumentNullException(nameof(myGetProvider)); } if (bambooProvider == null) { throw new ArgumentNullException(nameof(bambooProvider)); } if (continuaCIProvider == null) { throw new ArgumentNullException(nameof(continuaCIProvider)); } if (jenkinsProvider == null) { throw new ArgumentNullException(nameof(jenkinsProvider)); } if (bitriseProvider == null) { throw new ArgumentNullException(nameof(bitriseProvider)); } if (travisCIProvider == null) { throw new ArgumentNullException(nameof(travisCIProvider)); } if (bitbucketPipelinesProvider == null) { throw new ArgumentNullException(nameof(bitbucketPipelinesProvider)); } if (goCDProvider == null) { throw new ArgumentNullException(nameof(goCDProvider)); } if (gitlabCIProvider == null) { throw new ArgumentNullException(nameof(gitlabCIProvider)); } if (tfBuildProvider == null) { throw new ArgumentNullException(nameof(tfBuildProvider)); } AppVeyor = appVeyorProvider; TeamCity = teamCityProvider; MyGet = myGetProvider; Bamboo = bambooProvider; ContinuaCI = continuaCIProvider; Jenkins = jenkinsProvider; Bitrise = bitriseProvider; TravisCI = travisCIProvider; BitbucketPipelines = bitbucketPipelinesProvider; GoCD = goCDProvider; GitLabCI = gitlabCIProvider; TFBuild = tfBuildProvider; Provider = (AppVeyor.IsRunningOnAppVeyor ? BuildProvider.AppVeyor : BuildProvider.Local) | (TeamCity.IsRunningOnTeamCity ? BuildProvider.TeamCity : BuildProvider.Local) | (MyGet.IsRunningOnMyGet ? BuildProvider.MyGet : BuildProvider.Local) | (Bamboo.IsRunningOnBamboo ? BuildProvider.Bamboo : BuildProvider.Local) | (ContinuaCI.IsRunningOnContinuaCI ? BuildProvider.ContinuaCI : BuildProvider.Local) | (Jenkins.IsRunningOnJenkins ? BuildProvider.Jenkins : BuildProvider.Local) | (Bitrise.IsRunningOnBitrise ? BuildProvider.Bitrise : BuildProvider.Local) | (TravisCI.IsRunningOnTravisCI ? BuildProvider.TravisCI : BuildProvider.Local) | (BitbucketPipelines.IsRunningOnBitbucketPipelines ? BuildProvider.BitbucketPipelines : BuildProvider.Local) | (GoCD.IsRunningOnGoCD ? BuildProvider.GoCD : BuildProvider.Local) | (GitLabCI.IsRunningOnGitLabCI ? BuildProvider.GitLabCI : BuildProvider.Local) | (TFBuild.IsRunningOnAzurePipelines ? BuildProvider.AzurePipelines : BuildProvider.Local) | (TFBuild.IsRunningOnAzurePipelinesHosted ? BuildProvider.AzurePipelinesHosted : BuildProvider.Local); IsLocalBuild = Provider == BuildProvider.Local; IsPullRequest = ((Provider & BuildProvider.AppVeyor) != 0 && AppVeyor.Environment.PullRequest.IsPullRequest) || ((Provider & BuildProvider.TeamCity) != 0 && TeamCity.Environment.PullRequest.IsPullRequest) || ((Provider & BuildProvider.Bitrise) != 0 && Bitrise.Environment.PullRequest.IsPullRequest) || ((Provider & BuildProvider.TravisCI) != 0 && TravisCI.Environment.PullRequest.IsPullRequest) || ((Provider & BuildProvider.BitbucketPipelines) != 0 && BitbucketPipelines.Environment.PullRequest.IsPullRequest) || ((Provider & BuildProvider.GitLabCI) != 0 && GitLabCI.Environment.PullRequest.IsPullRequest) || ((Provider & (BuildProvider.AzurePipelines | BuildProvider.AzurePipelinesHosted)) != 0 && TFBuild.Environment.PullRequest.IsPullRequest); }
public static void UpdateProgress(this ITFBuildProvider provider, Guid parent, int progress) { provider.Commands.UpdateRecord(parent, new TFBuildRecordData { Progress = progress, Status = TFBuildTaskStatus.InProgress }); }
/// <summary> /// Initializes a new instance of the <see cref="BuildSystem" /> class. /// </summary> /// <param name="appVeyorProvider">The AppVeyor Provider.</param> /// <param name="teamCityProvider">The TeamCity Provider.</param> /// <param name="myGetProvider">The MyGet Provider.</param> /// <param name="bambooProvider">The Bamboo Provider.</param> /// <param name="continuaCIProvider">The Continua CI Provider.</param> /// <param name="jenkinsProvider">The Jenkins Provider.</param> /// <param name="bitriseProvider">The Bitrise Provider.</param> /// <param name="travisCIProvider">The Travis CI provider.</param> /// <param name="bitbucketPipelinesProvider">The Bitbucket Pipelines provider.</param> /// <param name="goCDProvider">The Go.CD provider.</param> /// <param name="gitlabCIProvider">The GitLab CI provider.</param> /// <param name="tfBuildProvider">The TF Build provider.</param> public BuildSystem( IAppVeyorProvider appVeyorProvider, ITeamCityProvider teamCityProvider, IMyGetProvider myGetProvider, IBambooProvider bambooProvider, IContinuaCIProvider continuaCIProvider, IJenkinsProvider jenkinsProvider, IBitriseProvider bitriseProvider, ITravisCIProvider travisCIProvider, IBitbucketPipelinesProvider bitbucketPipelinesProvider, IGoCDProvider goCDProvider, IGitLabCIProvider gitlabCIProvider, ITFBuildProvider tfBuildProvider) { if (appVeyorProvider == null) { throw new ArgumentNullException(nameof(appVeyorProvider)); } if (teamCityProvider == null) { throw new ArgumentNullException(nameof(teamCityProvider)); } if (myGetProvider == null) { throw new ArgumentNullException(nameof(myGetProvider)); } if (bambooProvider == null) { throw new ArgumentNullException(nameof(bambooProvider)); } if (continuaCIProvider == null) { throw new ArgumentNullException(nameof(continuaCIProvider)); } if (jenkinsProvider == null) { throw new ArgumentNullException(nameof(jenkinsProvider)); } if (bitriseProvider == null) { throw new ArgumentNullException(nameof(bitriseProvider)); } if (travisCIProvider == null) { throw new ArgumentNullException(nameof(travisCIProvider)); } if (bitbucketPipelinesProvider == null) { throw new ArgumentNullException(nameof(bitbucketPipelinesProvider)); } if (goCDProvider == null) { throw new ArgumentNullException(nameof(goCDProvider)); } if (gitlabCIProvider == null) { throw new ArgumentNullException(nameof(gitlabCIProvider)); } if (tfBuildProvider == null) { throw new ArgumentNullException(nameof(tfBuildProvider)); } AppVeyor = appVeyorProvider; TeamCity = teamCityProvider; MyGet = myGetProvider; Bamboo = bambooProvider; ContinuaCI = continuaCIProvider; Jenkins = jenkinsProvider; Bitrise = bitriseProvider; TravisCI = travisCIProvider; BitbucketPipelines = bitbucketPipelinesProvider; GoCD = goCDProvider; GitLabCI = gitlabCIProvider; TFBuild = tfBuildProvider; }
public VersionHelper(ICakeEnvironment environment, ICakeLog log, ICakeArguments arguments, IAppVeyorProvider appVeyorProvider, ITFBuildProvider azureProvider, IGlobber globber, IFileSystem fileSystem, IProcessRunner processRunner, IToolLocator tools) { _environment = environment; _log = log; _arguments = arguments; _appVeyorProvider = appVeyorProvider; _azureProvider = azureProvider; _globber = globber; _fileSystem = fileSystem; _processRunner = processRunner; _tools = tools; if (environment == null) { throw new ArgumentNullException(nameof(environment)); } if (log == null) { throw new ArgumentNullException(nameof(log)); } Configuration = environment.GetEnvironmentVariable("CONFIGURATION"); if (string.IsNullOrWhiteSpace(Configuration)) { Configuration = _arguments.HasArgument("configuration") ? _arguments.GetArgument("configuration") : "Release"; } string envLogging = environment.GetEnvironmentVariable("LOGGINGLEVEL"); if (!string.IsNullOrWhiteSpace(envLogging)) { Verbosity loggingEnum; if (Enum.TryParse(envLogging, true, out loggingEnum)) { log.Verbosity = loggingEnum; log.Information($"Logging Level: {loggingEnum}", Verbosity.Quiet); if (IsAppVeyor) { _appVeyorProvider.AddInformationalMessage($"Logging set by LoggingLevel enviornment variable to {loggingEnum}"); } _isDefaultLoggingLevel = false; } else { string msg = $"Invalid logging level [{envLogging}]. Use {Verbosity.Quiet}, {Verbosity.Minimal}, {Verbosity.Normal}, {Verbosity.Verbose} or {Verbosity.Diagnostic}"; if (IsAppVeyor) { log.Warning(msg); } _appVeyorProvider.AddWarningMessage(msg); } } else { _isDefaultLoggingLevel = !arguments.HasArgument("verbosity"); } if (_log.Verbosity > Verbosity.Normal) { var environmentVariables = environment.GetEnvironmentVariables(); foreach (string key in environmentVariables.Keys) { log.Verbose($"{key}:{environmentVariables[key]}"); } } CommitMessageMatches = new MatchResult { Success = false }; if (IsAppVeyor) { Branch = _appVeyorProvider.Environment.Repository.Branch; CommitMessageShort = _appVeyorProvider.Environment.Repository.Commit.Message; var match = CommitMessageRegex.Match(_appVeyorProvider.Environment.Repository.Commit.ExtendedMessage); CommitMessageMatches = new MatchResult { Success = match.Success, Groups = match.Groups }; _log.Debug($"Branch:{Branch}"); _log.Debug($"Commit Msg Short:{CommitMessageShort}"); _log.Debug($"Commit Msg Extended:{_appVeyorProvider.Environment.Repository.Commit.ExtendedMessage}"); _log.Debug($"Commit Message Cmd Match:{CommitMessageMatches.Success}"); if (_log.Verbosity >= Verbosity.Verbose && CommitMessageMatches.Success) { _log.Debug("RegEx Group Matches"); foreach (string groupName in CommitMessageRegex.GetGroupNames()) { _log.Debug($"{groupName} : {CommitMessageMatches.Groups[groupName].Value}"); } } } if (IsAzureDevops) { Branch = _azureProvider.Environment.Repository.Branch; //CommitMessageShort = _azureProvider.Environment.Repository.Commit.Message; //var match = CommitMessageRegex.Match(_azureProvider.Environment.Repository.Commit.ExtendedMessage); //CommitMessageMatches = new MatchResult { Success = match.Success, Groups = match.Groups }; //_log.Debug($"Branch:{Branch}"); //_log.Debug($"Commit Msg Short:{CommitMessageShort}"); //_log.Debug($"Commit Msg Extended:{_appVeyorProvider.Environment.Repository.Commit.ExtendedMessage}"); //_log.Debug($"Commit Message Cmd Match:{CommitMessageMatches.Success}"); //if (_log.Verbosity >= Verbosity.Verbose && CommitMessageMatches.Success) //{ // _log.Debug("RegEx Group Matches"); // foreach (string groupName in CommitMessageRegex.GetGroupNames()) // { // _log.Debug($"{groupName} : {CommitMessageMatches.Groups[groupName].Value}"); // } //} } }