/// <summary> /// Executes the logic for this workflow activity. /// </summary> /// <returns>The <see cref="Microsoft.TeamFoundation.Build.Client.IBuildDefinition"/> /// that is specified.</returns> protected override IBuildDefinition InternalExecute() { IBuildServer buildServer = this.BuildServer.Get(this.ActivityContext); string teamProjectName = this.TeamProjectName.Get(this.ActivityContext); string buildDefinitionName = this.BuildDefinitionName.Get(this.ActivityContext); return(buildServer.GetBuildDefinition(teamProjectName, buildDefinitionName)); }
public static void QueueBuild(string buildName) { string buildDefinitionInfo = System.Configuration.ConfigurationManager.AppSettings[buildName].ToString(); string projectCollectionUrl = System.Configuration.ConfigurationManager.AppSettings["projectCollectionUrl"]; TfsTeamProjectCollection teamProjectCollection = new TfsTeamProjectCollection(new Uri(projectCollectionUrl)); IBuildServer buildServer = (IBuildServer)teamProjectCollection.GetService(typeof(IBuildServer)); string projectName = buildDefinitionInfo.Split(';')[0]; string definitionName = buildDefinitionInfo.Split(';')[1]; IBuildDefinition buildDefinition = buildServer.GetBuildDefinition(projectName, definitionName, QueryOptions.Definitions); buildServer.QueueBuild(buildDefinition); }
/// <summary> /// Executes the logic for this workflow activity. /// </summary> /// <param name="context">The workflow context.</param> /// <returns>The <see cref="Microsoft.TeamFoundation.Build.Client.IBuildDefinition"/> /// that is specified.</returns> protected override IBuildDefinition Execute(CodeActivityContext context) { if (context == null) { throw new ArgumentNullException("context"); } IBuildServer buildServer = context.GetValue(this.BuildServer); string teamProjectName = context.GetValue(this.TeamProjectName); string buildDefinitionName = context.GetValue(this.BuildDefinitionName); IBuildDefinition buildDefinition = buildServer.GetBuildDefinition(teamProjectName, buildDefinitionName); return(buildDefinition); }
private IBuildDefinition CreateOrGetBuildDefinition( IBuildServer buildServer, string project, string buildDefinition, bool createBuildDefinitionIfNotExists, string buildController, string dropLocation) { try { return buildServer.GetBuildDefinition(project, buildDefinition); } catch (BuildDefinitionNotFoundException) { if (!createBuildDefinitionIfNotExists) throw; } Console.WriteLine("'{0}' does not exist, trying to create build definition", buildDefinition); return CreateBuildDefinition(buildServer, buildController, project, dropLocation, buildDefinition); }
public void QueueDefaultSubFolderBuilds() { // if (NodePriority == (int)TeamExplorerNodePriority.Leaf) // return; // just ignore, we should never be here IBuildServer buildServer = GetBuildServer(); foreach (IBuildDefinition buildDef in FindAssociated.AssociatedNodes(CanonicalName, this, separator).Select( item => buildServer.GetBuildDefinition(item.ProjectName, item.Name))) { if (buildDef.Enabled) { buildServer.QueueBuild(buildDef); } } BaseHierarchyNode node = FindAssociated.AssociatedNode("All Build Definitions", this, separator); node.ParentHierarchy.CallMethod("ViewBuilds", node); }
private IBuildDefinition CreateOrGetBuildDefinition( IBuildServer buildServer, string project, string buildDefinition, bool createBuildDefinitionIfNotExists, string buildController, string dropLocation) { try { return(buildServer.GetBuildDefinition(project, buildDefinition)); } catch (BuildDefinitionNotFoundException) { if (!createBuildDefinitionIfNotExists) { throw; } } Console.WriteLine("'{0}' does not exist, trying to create build definition", buildDefinition); return(CreateBuildDefinition(buildServer, buildController, project, dropLocation, buildDefinition)); }
public G19BuildScreenAppletModel GetBuildInformation(IBuildServer buildServer, string buildDefinition, string teamProject) { G19BuildScreenAppletModel model = new G19BuildScreenAppletModel(); IBuildDefinition buildDetailSpec = buildServer.GetBuildDefinition(teamProject, buildDefinition); IBuildDetail build = buildServer.GetBuild(buildDetailSpec.LastBuildUri); switch (build.Status) { case BuildStatus.Succeeded: model.Status = build.Status.ToString(); break; case BuildStatus.Failed: model.Status = build.Status.ToString(); break; case BuildStatus.InProgress: model.Status = build.Status.ToString(); break; case BuildStatus.PartiallySucceeded: model.Status = build.Status.ToString(); break; case BuildStatus.Stopped: model.Status = build.Status.ToString(); break; default: break; } model.RequestedBy = build.RequestedBy; model.TeamProjectName = build.TeamProject; model.TimeRequested = build.StartTime; model.BuildDefinitionName = build.BuildDefinition.Name; model.BuildUri = build.Uri; return model; }
public bool Execute() { // set up support for logging TaskLoggingHelper loggingHelper = new TaskLoggingHelper(this); // Log Variables loggingHelper.LogMessageFromText("Custom Task QueueBuild Starting", MessageImportance.High); loggingHelper.LogMessageFromText("tfsServer = " + tfsServer, MessageImportance.High); loggingHelper.LogMessageFromText("teamProject = " + teamProject, MessageImportance.High); loggingHelper.LogMessageFromText("buildDefinition = " + buildDefinition, MessageImportance.High); // Get the team foundation server TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(tfsServer); // Get the IBuildServer IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer)); // Get the build definition for which a build is to be queued IBuildDefinition buildDef = buildServer.GetBuildDefinition(teamProject, buildDefinition); // Create variable for queuedBuild and queue the build var queuedBuild = buildServer.QueueBuild(buildDef); loggingHelper.LogMessageFromText("Waiting for newly queued build from Team Project : " + teamProject + " : and Build Definition : " + buildDefinition + " : to complete", MessageImportance.High); loggingHelper.LogMessageFromText("Pinging queuedBuild : " + queuedBuild + " : every 5 seconds to confirm when build is complete", MessageImportance.High); // Wait for the completion of newly queued build - Will ping build every 5 seconds to confirm completion for a max of 5 hours queuedBuild.WaitForBuildCompletion(TimeSpan.FromSeconds(5), TimeSpan.FromHours(5)); loggingHelper.LogMessageFromText("Queued Build : " + queuedBuild.Build.BuildNumber + " has now completed", MessageImportance.High); loggingHelper.LogMessageFromText("Returning to original build", MessageImportance.High); return(true); }
/// <summary> /// Discover all available versions. /// </summary> /// <param name="name">The component name</param> /// <returns>A list with all versions</returns> public IEnumerable <IComponentVersion> GetAvailableVersions(IComponentName name) { var versList = new List <IComponentVersion>(); Logger.Instance().Log(TraceLevel.Info, "{0}: Querying available component versions...", ResolverType); var teamProject = _versionControlServer.TryGetTeamProject(name.TeamProject); if (teamProject == null) { Logger.Instance().Log( TraceLevel.Info, "{0}: Could not find team project {1} on version control server for team project collection {2}", ResolverType, name.TeamProject, ResolverSettings.GetSetting(ResolverValidSettings.TeamProjectCollectionUrl)); throw new InvalidComponentException( string.Format( "Could not find team project {0} on version control server for team project collection {1}", name.TeamProject, ResolverSettings.GetSetting(ResolverValidSettings.TeamProjectCollectionUrl))); } var buildDef = _buildServer.GetBuildDefinition(teamProject.Name, name.BuildDefinition); if (buildDef == null) { Logger.Instance().Log( TraceLevel.Info, "{0}: Could not find build definition {1} for team project {2} on version control server for tfs {3}", ResolverType, name.BuildDefinition, name.TeamProject, ResolverSettings.GetSetting(ResolverValidSettings.TeamProjectCollectionUrl)); throw new InvalidComponentException( string.Format( "Could not find build definition {0} for team project {1} on version control server for tfs {2}", name.BuildDefinition, name.TeamProject, ResolverSettings.GetSetting(ResolverValidSettings.TeamProjectCollectionUrl))); } // Query all builds with this teamProject and build definition name // BuildNumber xor (BuildQuality or BuildStatus) = version var spec = _buildServer.CreateBuildDetailSpec(buildDef); spec.InformationTypes = new string[] { }; var details = _buildServer.QueryBuilds(spec); foreach (var buildResult in details.Builds) { List <string> availableBuildQuality = null; if (buildResult.Quality != null) { availableBuildQuality = new List <string> { buildResult.Quality }; } var availableBuildStatus = new List <string> { buildResult.Status.ToString() }; var vers = new ComponentVersion(buildResult.BuildNumber, availableBuildStatus, availableBuildQuality, null); versList.Add(vers); Logger.Instance().Log(TraceLevel.Info, "{0}: Found build {1}", ResolverType, vers.ToString()); } Logger.Instance().Log(TraceLevel.Info, "{0}: Querying component versions finished successfully", ResolverType); return(versList); }