private static void ApplyRetainBuild(Mapping mapping, DeployAgentResult deployAgentResult, IBuildDetail detail) { if (!mapping.RetainBuildSpecified) { return; } if (deployAgentResult.HasErrors) { return; } // no change to setting? if (detail.KeepForever == mapping.RetainBuild) { return; } detail.KeepForever = mapping.RetainBuild; try { detail.Save(); } catch (AccessDeniedException ex) { deployAgentResult.Output = string.Format("{0}\n{1}", deployAgentResult.Output, ex); } }
protected void LogBuildError(string errorMessage) { if (this.FailBuildOnError.Get(this.ActivityContext)) { this.failingbuild = true; IBuildDetail extension = this.ActivityContext.GetExtension <IBuildDetail>(); extension.Status = BuildStatus.Failed; extension.Save(); throw new Exception(errorMessage); } this.ActivityContext.TrackBuildError(errorMessage); }
protected virtual void Dispose(bool disposing) { if (!disposed && disposing && teamProjectCollection != null) { build.Save(); teamProjectCollection.Dispose(); teamProjectCollection = null; build = null; } disposed = true; }
protected override void Execute(CodeActivityContext context) { if (context == null) { throw new ArgumentNullException("context"); } if (!this.BuildNumberFormat.Get(context).Contains(VersionReplaceToken)) { string message = string.Format(CultureInfo.CurrentCulture, "The 'BuildNumberFormat' value did not contain '{0}' as required (this will be replaced by the version number).", VersionReplaceToken); throw new ArgumentException(message); } IBuildDetail buildDetail = context.GetExtension <IBuildDetail>(); BuildServerFacade buildServerFacade = new BuildServerFacade(buildDetail.BuildServer); DateTime dateOfBuild = DateTime.Now; // e.g. latestBuildNumberFromAllBuildDefinitions = "Acme.PetShop-Trunk-Full-0.0.11114.3" string[] latestBuildNumbersFromAllBuildDefinitions = buildServerFacade.GetLatestBuildNumbersFromAllBuildDefinitions(buildDetail.TeamProject, 10); Version nextVersionNumber; if (latestBuildNumbersFromAllBuildDefinitions.Length < 1) { // No previous builds at all so just create a new version from scratch. nextVersionNumber = GetFreshVersionNumber(this.MajorVersion.Get(context), this.MinorVersion.Get(context), dateOfBuild); } else { Version latestVersionNumber = GetLatestVersionNumberFromPreviousBuildNumbers(latestBuildNumbersFromAllBuildDefinitions); if (latestVersionNumber == null) { // The previous build number was not found to have a version number contained in it. nextVersionNumber = GetFreshVersionNumber(this.MajorVersion.Get(context), this.MinorVersion.Get(context), dateOfBuild); } else { // We found a version number in the previous build number so increment it. nextVersionNumber = GetNextVersionNumber(latestVersionNumber, this.MajorVersion.Get(context), this.MinorVersion.Get(context), dateOfBuild); } } string nextBuildNumber = string.Format(CultureInfo.CurrentCulture, this.BuildNumberFormat.Get(context), nextVersionNumber); this.BuildNumber.Set(context, nextBuildNumber); this.VersionNumber.Set(context, nextVersionNumber.ToString()); buildDetail.BuildNumber = nextBuildNumber; buildDetail.Save(); }
private static void ApplyRetainBuild(Mapping mapping, IRunner runner, IBuildDetail detail) { if (!mapping.RetainBuildSpecified) { return; } if (runner.ErrorOccurred) { return; } if (detail.KeepForever == mapping.RetainBuild) { return; } detail.KeepForever = mapping.RetainBuild; detail.Save(); }
private static void ApplyRetainBuild(Mapping mapping, DeployAgentResult deployAgentResult, IBuildDetail detail) { if (!mapping.RetainBuildSpecified) { return; } if (deployAgentResult.HasErrors) { return; } if (detail.KeepForever == mapping.RetainBuild) { return; } detail.KeepForever = mapping.RetainBuild; detail.Save(); }
/// <summary> /// Executes the logic for this custom activity /// </summary> protected override void InternalExecute() { Workspace workspace = this.BuildWorkspace.Get(this.ActivityContext); string sonarRunnerPath = this.SonarRunnerPath.Get(this.ActivityContext); if (!File.Exists(sonarRunnerPath)) { this.LogBuildError("Sonar runner file not found: " + sonarRunnerPath); return; } foreach (string projectToAnalyze in this.ProjectsToAnalyze.Get(this.ActivityContext)) { if (!string.IsNullOrWhiteSpace(projectToAnalyze)) { string localProjectPath = workspace.GetLocalItemForServerItem(projectToAnalyze); string localFolderPath = System.IO.Path.GetDirectoryName(localProjectPath); if (this.GeneratePropertiesIfMissing.Get(this.ActivityContext)) { string sonarPropertiesPath = Path.Combine(localFolderPath, this.SonarPropertiesFileName.Get(this.ActivityContext)); string templatePropertiesPath = this.SonarPropertiesTemplatePath.Get(this.ActivityContext); if (!File.Exists(sonarPropertiesPath)) { this.LogBuildMessage("sonar.properties file not found in working folder."); if (!string.IsNullOrWhiteSpace(templatePropertiesPath)) { if (File.Exists(templatePropertiesPath)) { this.LogBuildMessage("Generating sonar properties file from " + templatePropertiesPath); string properties = this.TransformSonarProperties( templatePropertiesPath, localProjectPath); this.LogBuildMessage(properties, BuildMessageImportance.Low); File.WriteAllText(sonarPropertiesPath, properties, Encoding.ASCII); } else { this.LogBuildError("Sonar properties template file not found " + templatePropertiesPath); } } else { this.LogBuildError("No sonar properties file found and no template path set up."); } } } string arguments = string.Format("/c \"{0}\"", this.SonarRunnerPath.Get(this.ActivityContext)); SonarRunResult result = this.RunProcess("cmd.exe", localFolderPath, arguments); if (result.HasBreakingAlerts) { this.LogBuildError("Sonar analysis has raised critical alerts."); if (this.FailBuildOnAlert.Get(this.ActivityContext)) { IBuildDetail buildDetail = this.ActivityContext.GetExtension <IBuildDetail>(); buildDetail.Status = BuildStatus.Failed; buildDetail.Save(); } } else { if (result.ReturnCode == 0) { this.LogBuildMessage("Sonar analysis successful.", BuildMessageImportance.High); } else { this.LogBuildError("Sonar analysis has failed."); } } } } }