public IActionResult GetJobParameters(string jenkinsUrl, string name) { JenkinsConfig config = new JenkinsConfig() { JenkinsUrl = jenkinsUrl }; JenkinsClient client = new JenkinsClient(config); CancellationToken token = new CancellationToken(); var job = client.GetJob(name, token).Result; try { List <JenkinsJobParameter> parameters = new List <JenkinsJobParameter>(); var par = job.Actions.Where(a => a["parameterDefinitions"] != null).FirstOrDefault(); foreach (var item in par["parameterDefinitions"].Children()) { var p = Newtonsoft.Json.JsonConvert.DeserializeObject <JsonJobParameter>(item.ToString()); parameters.Add(new JenkinsJobParameter() { Name = p.Name, DataType = p.Type, DefaultValue = p.DefaultParameterValue.Value }); } return(Json(parameters)); } catch { } return(Json(false)); }
public IActionResult GetJob(string jenkinsUrl, string name) { JenkinsConfig config = new JenkinsConfig() { JenkinsUrl = jenkinsUrl }; JenkinsClient client = new JenkinsClient(config); CancellationToken token = new CancellationToken(); var job = client.GetJob(name, token).Result; int?health = job.HealthReport.FirstOrDefault()?.Score; // var lastBuild = client.GetBuild(name, job.LastBuild.Number.ToString(), token).Result; string lastBuildResult = "UNKNOWN"; if (job.LastBuild != null && job.LastSuccessfulBuild != null) { lastBuildResult = job.LastBuild.Number == job.LastSuccessfulBuild.Number ? "SUCCESS" : "FAILED"; } // string lastBuildResult = (DateTime.Now.Millisecond % 2 == 0) ? "SUCCESS" : "FAILED"; var result = new JenkinsJob() { Name = job.Name, Color = job.Color, Building = job.Color.Contains("anime"), Url = job.Url.ToString(), Buildable = job.Buildable, Health = health.GetValueOrDefault(-1), LastBuild = new JenkinsBuild() { Url = job.LastBuild.Url.ToString(), Number = job.LastBuild.Number, Result = lastBuildResult }, }; return(Json(result)); }