示例#1
0
        public override Connector CreateNew(ConnectorConfiguration configuration)
        {
            log.Debug("Creating new JenkinsProject based on configuration {configuration}", new { configuration.Name, configuration.Identifier });
            var jenkinsProject = new JenkinsConnector(configuration, new JenkinsApi());

            return(jenkinsProject);
        }
        public async Task <IList <JenkinsBuild> > GetBuilds(JenkinsConnector connector, CancellationToken token, int from = 0, int to = Connector.MaxSnapshots)
        {
            var buildsRequest = UrlHelper.BuildsRequest(connector, from, to);
            var builds        = await SerializationHelper.Instance.GetJsonModel <JenkinsBuilds>(buildsRequest, token);

            return(builds?.Builds ?? new List <JenkinsBuild>());
        }
示例#3
0
            public static string BuildUrl(JenkinsConnector connector, int buildNumber, bool appendRedirect = true)
            {
                var url = $"{SanitizeBaseUrl(connector.Address)}/{GetRelativeProjectUrl(connector)}/{buildNumber}";

                if (appendRedirect && bool.TryParse(connector.Configuration.GetConfigurationByKey(JenkinsConnector.RedirectPlugin)?.Value, out var redirect) && redirect)
                {
                    return($"{url}{RedirectPluginUrlSuffix}");
                }

                return(url);
            }
示例#4
0
        public async Task <JenkinsBuild> GetJenkinsBuild(JenkinsConnector connector, int buildNumber, CancellationToken token)
        {
            var buildRequest = UrlHelper.BuildRequest(connector, buildNumber);

            try
            {
                return(await SerializationHelper.Instance.GetJsonModel <JenkinsBuild>(buildRequest, token));
            }
            catch (Exception)
            {
                return(null);
            }
        }
示例#5
0
        public async Task <JenkinsJob> GetJenkinsJob(JenkinsConnector connector, CancellationToken token)
        {
            var jobRequest = UrlHelper.JobRequest(connector);

            try
            {
                return(await SerializationHelper.Instance.GetJsonModel <JenkinsJob>(jobRequest, token));
            }
            catch (Exception)
            {
                return(null);
            }
        }
示例#6
0
        public override Connector CreateNew(ConnectorConfiguration configuration, bool?checkRedirect = null)
        {
            log.Debug("Creating new JenkinsProject based on configuration {configuration}", new { configuration.Name, configuration.Identifier });
            var jenkinsProject = new JenkinsConnector(configuration, new JenkinsApi());

            if (checkRedirect == null)
            {
                return(jenkinsProject);
            }
            else if (checkRedirect == false)
            {
                return(jenkinsProject);
            }

            if (blueOceanCache.ContainsKey(jenkinsProject.Address))
            {
                jenkinsProject.Configuration.GetConfigurationByKey("RedirectPlugin").Value = blueOceanCache[jenkinsProject.Address].ToString();
                configuration.GetConfigurationByKey("RedirectPlugin").Value = blueOceanCache[jenkinsProject.Address].ToString();
                return(jenkinsProject);
            }

            var task = Task.Run(async() => await jenkinsProject.IsReachableUrl(JenkinsApi.UrlHelper.ProjectUrl(jenkinsProject) + JenkinsApi.UrlHelper.RedirectPluginUrlSuffix));

            task.Wait();
            var result = task.Result;

            if (result == true)
            {
                jenkinsProject.Configuration.GetConfigurationByKey("RedirectPlugin").Value = "True";
                configuration.GetConfigurationByKey("RedirectPlugin").Value = "True";
                blueOceanCache.Add(jenkinsProject.Address, true);
            }
            else
            {
                blueOceanCache.Add(jenkinsProject.Address, false);
            }

            return(jenkinsProject);
        }
示例#7
0
 public static string JobRequest(JenkinsConnector connector)
 {
     return($"{SanitizeBaseUrl(connector.Address)}/{GetRelativeProjectUrl(connector)}/api/json?tree={JenkinsJob.RequestProperties}");
 }
示例#8
0
 public static string BuildsRequest(JenkinsConnector connector, int from, int to)
 {
     return($"{SanitizeBaseUrl(connector.Address)}/{GetRelativeProjectUrl(connector)}/api/json?tree=builds[{JenkinsBuild.RequestProperties}]{{{from},{to}}}");
 }
示例#9
0
 public static string BuildRequest(JenkinsConnector connector, int buildNumber)
 {
     return($"{BuildUrl(connector, buildNumber, false)}/api/json?tree={JenkinsBuild.RequestProperties}");
 }