コード例 #1
0
        /// <param name="rootUrl">Must not end with /</param>
        public static BambooBuildStatus CreateBuildResult(XDocument doc, BuildDefinitionSetting buildDefinitionSetting, string rootUrl)
        {
            BambooBuildStatus result = new BambooBuildStatus
            {
                BuildDefinitionId = buildDefinitionSetting.Id,
                Name = buildDefinitionSetting.Name
            };

            if (doc.Root == null)
            {
                throw new Exception("Invalid root element");
            }

            var stateStr = doc.Root.AttributeValueOrDefault("state");

            result.StartedTime  = ParseDateTime(doc.Root.ElementValueOrDefault("buildStartedTime"));
            result.FinishedTime = ParseDateTime(doc.Root.ElementValueOrDefault("buildCompletedTime"));

            result.BuildStatusEnum = ToBuildStatusEnum(stateStr);

            var changesElem = doc.Root.Element("changes");

            if (changesElem != null)
            {
                var changeElem = changesElem.Element("change");
                if (changeElem != null)
                {
                    result.RequestedBy = changeElem.AttributeValueOrDefault("author");
                    result.Comment     = changeElem.ElementValueOrDefault("comment");
                }
            }

            result.BuildId = doc.Root.AttributeValueOrDefault("number");
            string buildKey = doc.Root.AttributeValueOrDefault("key"); // i.e. the "plan key"

            result.Url = rootUrl + "/browse/" + buildKey;

            if (string.IsNullOrWhiteSpace(result.RequestedBy) && string.IsNullOrWhiteSpace(result.Comment))
            {
                var buildReason = doc.Root.ElementValueOrDefault("buildReason");
                result.Comment     = GetCommentFromBuildReason(buildReason);
                result.RequestedBy = GetUserFromBuildReason(buildReason);
            }

            return(result);
        }
コード例 #2
0
        /// <param name="rootUrl">Must not end with /</param>
        public static BambooBuildStatus CreateBuildResult(XDocument doc, BuildDefinitionSetting buildDefinitionSetting, string rootUrl)
        {
            BambooBuildStatus result = new BambooBuildStatus
            {
                BuildDefinitionId = buildDefinitionSetting.Id,
                Name = buildDefinitionSetting.Name
            };

            if (doc.Root == null) throw new Exception("Invalid root element");

            var stateStr = doc.Root.AttributeValueOrDefault("state");

            result.StartedTime = ParseDateTime(doc.Root.ElementValueOrDefault("buildStartedTime"));
            result.FinishedTime = ParseDateTime(doc.Root.ElementValueOrDefault("buildCompletedTime"));

            result.BuildStatusEnum = ToBuildStatusEnum(stateStr);

            var changesElem = doc.Root.Element("changes");
            if (changesElem != null)
            {
                var changeElem = changesElem.Element("change");
                if (changeElem != null)
                {
                    result.RequestedBy = changeElem.AttributeValueOrDefault("author");
                    result.Comment = changeElem.ElementValueOrDefault("comment");
                }
            }

            result.BuildId = doc.Root.AttributeValueOrDefault("number");
            string buildKey = doc.Root.AttributeValueOrDefault("key"); // i.e. the "plan key"
            result.Url = rootUrl + "/browse/" + buildKey;

            if (string.IsNullOrWhiteSpace(result.RequestedBy) && string.IsNullOrWhiteSpace(result.Comment))
            {
                var buildReason = doc.Root.ElementValueOrDefault("buildReason");
                result.Comment = GetCommentFromBuildReason(buildReason);
                result.RequestedBy = GetUserFromBuildReason(buildReason);
            }

            return result;
        }
コード例 #3
0
        public static BambooBuildStatus CreateIsBuilding(BuildDefinitionSetting buildDefinitionSetting)
        {
            BambooBuildStatus result = new BambooBuildStatus
            {
                BuildDefinitionId = buildDefinitionSetting.Id,
                Name = buildDefinitionSetting.Name,
                BuildStatusEnum = BuildStatusEnum.InProgress
            };

            DateTime startTime;
            if (_startTimeLookup.TryGetValue(buildDefinitionSetting.Id, out startTime))
            {
                result.StartedTime = startTime;
            }
            else
            {
                result.StartedTime = DateTime.Now;
                _startTimeLookup.Add(buildDefinitionSetting.Id, result.StartedTime.Value);
            }

            return result;
        }
コード例 #4
0
        private BambooBuildStatus GetBuildStatus(string rootUrl, BuildDefinitionSetting buildDefinitionSetting, string userName, string password)
        {
            try
            {
                string    planUrl    = rootUrl + "/rest/api/latest/plan/" + buildDefinitionSetting.Id + "?os_authType=basic";
                XDocument planDoc    = DownloadXml(planUrl, userName, password);
                var       isBuilding = planDoc.Root.ElementValueAsBool("isBuilding", false);
                if (isBuilding != null && isBuilding.Value)
                {
                    return(BambooBuildStatus.CreateIsBuilding(buildDefinitionSetting));
                }

                XDocument buildDoc;
                try
                {
                    string buildUrl = rootUrl + "/rest/api/latest/result/" + buildDefinitionSetting.Id + "-latest?expand=changes.change&os_authType=basic";
                    buildDoc = DownloadXml(buildUrl, userName, password);
                }
                catch (Exception)
                {
                    string buildUrl = rootUrl + "/rest/api/latest/build/" + buildDefinitionSetting.Id + "-latest?expand=changes.change&os_authType=basic";
                    buildDoc = DownloadXml(buildUrl, userName, password);
                }
                if (buildDoc.Root == null)
                {
                    throw new Exception("Could not get project status");
                }
                return(BambooBuildStatus.CreateBuildResult(buildDoc, buildDefinitionSetting, rootUrl));
            }
            catch (SosException ex)
            {
                if (ex.Message.Contains("not found"))
                {
                    throw new BuildDefinitionNotFoundException(buildDefinitionSetting);
                }
                throw;
            }
        }
コード例 #5
0
        public static BambooBuildStatus CreateIsBuilding(BuildDefinitionSetting buildDefinitionSetting)
        {
            BambooBuildStatus result = new BambooBuildStatus
            {
                BuildDefinitionId = buildDefinitionSetting.Id,
                Name            = buildDefinitionSetting.Name,
                BuildStatusEnum = BuildStatusEnum.InProgress
            };

            DateTime startTime;

            if (_startTimeLookup.TryGetValue(buildDefinitionSetting.Id, out startTime))
            {
                result.StartedTime = startTime;
            }
            else
            {
                result.StartedTime = DateTime.Now;
                _startTimeLookup.Add(buildDefinitionSetting.Id, result.StartedTime.Value);
            }

            return(result);
        }