Exemplo n.º 1
0
        /// <summary>
        /// Rets the last two builds for all build definitions matching the passe din parameters
        /// </summary>
        /// <param name="teamProject">the team project to uery against</param>
        /// <param name="buildDefinitionPattern">optional build definition pattern</param>
        /// <returns>build result pairs</returns>
        public TfsLastTwoBuildResults[] GetLastTwoBuilds(TeamProject teamProject, string buildDefinitionPattern)
        {
            log.Debug("Finding build results for definition pattern " + buildDefinitionPattern);
            IBuildDetailSpec buildDetailsQuerySpec;

            if (buildDefinitionPattern != null)
            {
                buildDetailsQuerySpec = this.Connection.BuildServer.CreateBuildDetailSpec(teamProject.Name, buildDefinitionPattern);
            }
            else
            {
                buildDetailsQuerySpec = this.Connection.BuildServer.CreateBuildDetailSpec(teamProject.Name);
            }
            //// Failure to set this property results in ALL of the build information being retrieved resulting in 10X+ call times
            //// You can retrieve subsets with something like
            //// buildDetailsQuerySpec.InformationTypes = new string[] { "ActivityTracking", "AgentScopeActivityTracking" };
            buildDetailsQuerySpec.InformationTypes = null;
            //// last and previous
            buildDetailsQuerySpec.MaxBuildsPerDefinition = 2;
            //// use start time descending because InProgress builds don't seem to sort correctly when using EndTimeDescending
            buildDetailsQuerySpec.QueryOrder = BuildQueryOrder.StartTimeDescending;
            IBuildQueryResult buildResults = this.Connection.BuildServer.QueryBuilds(buildDetailsQuerySpec);

            IDictionary <string, TfsLastTwoBuildResults> results = new SortedDictionary <string, TfsLastTwoBuildResults>();

            //// create placeholder result objects, one for each build, that we will fill with results
            foreach (IBuildDetail oneDetail in buildResults.Builds)
            {
                if (!results.ContainsKey(oneDetail.BuildDefinition.Name))
                {
                    results.Add(oneDetail.BuildDefinition.Name, new TfsLastTwoBuildResults(oneDetail.BuildDefinition, null, null));
                }
            }
            //// now fill the results.
            //// The builds are in reverse start time order so the last build shold always be first putting it in the last build slot
            foreach (IBuildDetail oneDetail in buildResults.Builds)
            {
                TfsLastTwoBuildResults corresponding = results[oneDetail.BuildDefinition.Name];
                //// sorted by start time descending so latest should always come first
                if (corresponding.LastBuild == null)
                {
                    corresponding.LastBuild = oneDetail;
                }
                else
                {
                    corresponding.PreviousBuild = oneDetail;
                }
            }

            if (log.IsDebugEnabled)
            {
                foreach (string key in results.Keys)
                {
                    TfsLastTwoBuildResults oneResult = results[key];
                    log.Debug(" " + oneResult.BuildDefinition.Name);
                    log.Debug("  " + oneResult.LastBuild.BuildNumber + " " + oneResult.LastBuild.Status);
                    if (oneResult.PreviousBuild != null)
                    {
                        log.Debug("  " + oneResult.PreviousBuild.BuildNumber + " " + oneResult.PreviousBuild.Status);
                    }
                }
            }
            //// convert the dictionary to an array
            TfsLastTwoBuildResults[] resultsAsArray = new TfsLastTwoBuildResults[results.Values.Count];
            results.Values.CopyTo(resultsAsArray, 0);
            return(resultsAsArray);
        }
Exemplo n.º 2
0
        /// <summary>
        /// used to tell user if any builds in this set are in progress
        /// </summary>
        /// <param name="buildResults">buld results to be analyzed</param>
        /// <returns>number of builds In Progress</returns>
        public int SomeoneIsBuilding(TfsLastTwoBuildResults[] buildResults)
        {
            int buildCount = 0;
            foreach (TfsLastTwoBuildResults buildResult in buildResults)
            {
                if (buildResult.LastBuild.Status == BuildStatus.InProgress)
                {
                    log.Debug("Found build in progress: " + buildResult.BuildDefinition.Name);
                    buildCount++;
                }
            }

            return buildCount;
        }
Exemplo n.º 3
0
        public int NumberOfSuccessfulBuilds(TfsLastTwoBuildResults[] buildResults)
        {
            int successfulBuildCount = 0;
            foreach (TfsLastTwoBuildResults buildResult in buildResults)
            {
                if (buildResult.LastBuild.Status == BuildStatus.InProgress)
                {
                    // treat as not successful if in progress and was no previous build
                    if (buildResult.PreviousBuild != null && buildResult.PreviousBuild.Status != BuildStatus.Succeeded)
                    {
                        log.Debug("Found previous build that was not fully successful " + buildResult.BuildDefinition.Name + " - " + buildResult.PreviousBuild.Status);
                    }
                    else
                    {
                        successfulBuildCount++;
                    }
                }
                else
                {
                    if (buildResult.LastBuild != null && buildResult.LastBuild.Status != BuildStatus.Succeeded)
                    {
                        //// not in progress and last build did not succeed
                        log.Debug("Found last build that was not fully successful " + buildResult.BuildDefinition.Name + " - " + buildResult.LastBuild.Status);
                    }
                    else
                    {
                        successfulBuildCount++;
                    }
                }
            }

            if (successfulBuildCount == buildResults.Length)
            {
                log.Debug("All builds were completely successful");
            }
            //// assume success
            return successfulBuildCount;
        }
Exemplo n.º 4
0
        public int NumberOfPartiallySuccessfulBuilds(TfsLastTwoBuildResults[] buildResults)
        {
            int partiallySuccessfulBuildCount = 0;
            foreach (TfsLastTwoBuildResults buildResult in buildResults)
            {
                if (buildResult.LastBuild.Status == BuildStatus.InProgress)
                {
                    if (buildResult.PreviousBuild != null
                        && buildResult.PreviousBuild.Status == BuildStatus.PartiallySucceeded)
                    {
                        partiallySuccessfulBuildCount++;
                    }
                }
                else
                {
                    if (buildResult.LastBuild != null
                            && buildResult.LastBuild.Status == BuildStatus.PartiallySucceeded)
                    {
                        partiallySuccessfulBuildCount++;
                    }
                }
            }

            if (partiallySuccessfulBuildCount > 0)
            {
                log.Debug(partiallySuccessfulBuildCount + " builds were partially successful");
            }
            return partiallySuccessfulBuildCount;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Rets the last two builds for all build definitions matching the passe din parameters
        /// </summary>
        /// <param name="teamProject">the team project to uery against</param>
        /// <param name="buildDefinitionPattern">optional build definition pattern</param>
        /// <returns>build result pairs</returns>
        public TfsLastTwoBuildResults[] GetLastTwoBuilds(TeamProject teamProject, string buildDefinitionPattern)
        {
            log.Debug("Finding build results for definition pattern " + buildDefinitionPattern);
            IBuildDetailSpec buildDetailsQuerySpec;
            if (buildDefinitionPattern != null)
            {
                buildDetailsQuerySpec = this.Connection.BuildServer.CreateBuildDetailSpec(teamProject.Name, buildDefinitionPattern);
            }
            else
            {
                buildDetailsQuerySpec = this.Connection.BuildServer.CreateBuildDetailSpec(teamProject.Name);
            }
            //// Failure to set this property results in ALL of the build information being retrieved resulting in 10X+ call times
            //// You can retrieve subsets with something like
            //// buildDetailsQuerySpec.InformationTypes = new string[] { "ActivityTracking", "AgentScopeActivityTracking" };
            buildDetailsQuerySpec.InformationTypes = null;
            //// last and previous
            buildDetailsQuerySpec.MaxBuildsPerDefinition = 2;
            //// use start time descending because InProgress builds don't seem to sort correctly when using EndTimeDescending
            buildDetailsQuerySpec.QueryOrder = BuildQueryOrder.StartTimeDescending;
            IBuildQueryResult buildResults = this.Connection.BuildServer.QueryBuilds(buildDetailsQuerySpec);

            IDictionary<string, TfsLastTwoBuildResults> results = new SortedDictionary<string, TfsLastTwoBuildResults>();
            //// create placeholder result objects, one for each build, that we will fill with results
            foreach (IBuildDetail oneDetail in buildResults.Builds)
            {
                if (!results.ContainsKey(oneDetail.BuildDefinition.Name))
                {
                    results.Add(oneDetail.BuildDefinition.Name, new TfsLastTwoBuildResults(oneDetail.BuildDefinition, null, null));
                }
            }
            //// now fill the results.
            //// The builds are in reverse start time order so the last build shold always be first putting it in the last build slot
            foreach (IBuildDetail oneDetail in buildResults.Builds)
            {
                TfsLastTwoBuildResults corresponding = results[oneDetail.BuildDefinition.Name];
                //// sorted by start time descending so latest should always come first
                if (corresponding.LastBuild == null)
                {
                    corresponding.LastBuild = oneDetail;
                }
                else
                {
                    corresponding.PreviousBuild = oneDetail;
                }
            }

            if (log.IsDebugEnabled)
            {
                foreach (string key in results.Keys)
                {
                    TfsLastTwoBuildResults oneResult = results[key];
                    log.Debug(" " + oneResult.BuildDefinition.Name);
                    log.Debug("  " + oneResult.LastBuild.BuildNumber + " " + oneResult.LastBuild.Status);
                    if (oneResult.PreviousBuild != null)
                    {
                        log.Debug("  " + oneResult.PreviousBuild.BuildNumber + " " + oneResult.PreviousBuild.Status);
                    }
                }
            }
            //// convert the dictionary to an array
            TfsLastTwoBuildResults[] resultsAsArray = new TfsLastTwoBuildResults[results.Values.Count];
            results.Values.CopyTo(resultsAsArray, 0);
            return resultsAsArray;
        }
 /// <summary>
 /// external entities provide data for this page
 /// </summary>
 /// <param name="key">The grouping key, usually the build name pattern used to run the TFS query</param>
 /// <param name="oneBuildSet">The results of all the builds retrieved as a group under the key</param>
 public void AddData(String key, TfsLastTwoBuildResults[] oneBuildSet)
 {
     buildResults[key] = oneBuildSet;
 }