Beispiel #1
0
 private void NotifyListeners(JenkinsJob UpdatedJob)
 {
     if (eventListeners != null)
     {
         eventListeners(UpdatedJob);
     }
 }
Beispiel #2
0
        public JenkinsWorkflow GetJobReport(JenkinsJob Job)
        {
            string jobQueryUrl = GetJobReportUrl(Job.JobUrl, Job.IsTemporary);

            try
            {
                HttpWebResponse httpWebResponse = client.Get(jobQueryUrl);
                if (httpWebResponse.StatusCode == HttpStatusCode.OK)
                {
                    using (var reader = new System.IO.StreamReader(httpWebResponse.GetResponseStream(), ASCIIEncoding.ASCII))
                    {
                        string          responseData = reader.ReadToEnd();
                        JenkinsWorkflow resultData   = null;
                        if (Job.IsTemporary)
                        {
                            resultData = (WorkflowRun)JsonConvert.DeserializeObject(responseData, typeof(WorkflowRun));
                        }
                        else
                        {
                            resultData = (WorkflowJob)JsonConvert.DeserializeObject(responseData, typeof(WorkflowJob));
                        }
                        eventHandler.ConnectionWorks();
                        return(resultData);
                    }
                }
            }
            catch (Exception e)
            {
                eventHandler.ConnectionError("Jenkins data error!", e.Message);
            }
            return(null);
        }
Beispiel #3
0
        public bool MoveJobIndexDown(JenkinsJob Job)
        {
            int index = Job.Index;

            if (index == lastIndex)
            {
                return(false);
            }
            int        lowest_bigger_index = lastIndex;
            JenkinsJob lbiJob = null;

            foreach (JenkinsJob j in jobs)
            {
                if (j.Index <= lowest_bigger_index && j.Index > index)
                {
                    lowest_bigger_index = j.Index;
                    lbiJob = j;
                }
            }
            if (lbiJob != null)
            {
                lbiJob.Index = Job.Index;
                Job.Index    = lowest_bigger_index;
                return(true);
            }
            return(false);
        }
Beispiel #4
0
        public bool MoveJobIndexUp(JenkinsJob Job)
        {
            int index = Job.Index;

            if (index == 0)
            {
                return(false);
            }
            int        biggest_lower_index = 0;
            JenkinsJob bliJob = null;

            foreach (JenkinsJob j in jobs)
            {
                if (j.Index >= biggest_lower_index && j.Index < index)
                {
                    biggest_lower_index = j.Index;
                    bliJob = j;
                }
            }
            if (bliJob != null)
            {
                bliJob.Index = Job.Index;
                Job.Index    = biggest_lower_index;
                return(true);
            }
            return(false);
        }
Beispiel #5
0
        public bool UpdateJob(JenkinsJob Job, bool Notify = true)
        {
            if (Job.IsTemporary && !Job.Building)
            {
                if (Job.RemoveIfCompleted)
                {
                    RemoveJob(Job);
                }
                return(true);   // Temporary jobs done are not updated
            }

            JenkinsWorkflow updatedJob = GetJobReport(Job);

            if (updatedJob == null)
            {
                return(false);
            }
            JenkinsJob oldJob = Job.Clone() as JenkinsJob;

            Job.UpdateJobStatus(updatedJob);
            if (Notify && oldJob.DoNotify(updatedJob))
            {
                NotifyListeners(Job);
            }
            return(true);
        }
Beispiel #6
0
 public void RemoveJob(JenkinsJob Job)
 {
     lock (jobs)
     {
         jobs.Remove(Job);
     }
     eventHandler.JobRemoved(Job);
 }
Beispiel #7
0
        public override bool Equals(object obj)
        {
            JenkinsJob job = obj as JenkinsJob;

            if (job == null)
            {
                return(false);
            }
            return(this.id == job.id);
        }
Beispiel #8
0
        public void AddNewJob(JenkinsJob NewJob)
        {
            JenkinsWorkflow job = GetJobReport(NewJob);

            if (job == null)
            {
                return;
            }
            NewJob.UpdateJobStatus(job);
            lock (jobs)
            {
                this.jobs.Add(NewJob);
            }
            lastIndex = NewJob.Index;
            eventHandler.JobAdded(NewJob);
        }
Beispiel #9
0
        public void StartNewJobFromTemplate(JenkinsTemplate Template, string JobName)
        {
            JenkinsJob  newJob = new JenkinsJob(JobName, Template.JobUrl, false, lastIndex + 1);
            WorkflowJob job    = GetJobReport(newJob) as WorkflowJob;
            int         lastBuildNumberOfJob = job.lastBuild.number;

            string          jobInputParams = GetJsonInput(Template.GetInput());
            HttpWebResponse response       = client.Post(Template.BuildJobUrl, jobInputParams);
            string          location       = response.Headers["Location"];

            Threading.Thread adder = new Threading.Thread(() =>
            {
                int numOfMaxTrial = 20;
                int lastNumber    = lastBuildNumberOfJob;
                do
                {
                    Threading.Thread.Sleep(2000);
                    WorkflowJob report = GetJobReport(newJob) as WorkflowJob;
                    if (report != null)
                    {
                        lastNumber = report.lastBuild.number;
                    }
                    numOfMaxTrial--;
                }while (lastBuildNumberOfJob == lastNumber && numOfMaxTrial > 0);

                newJob.IsTemporary       = true;
                newJob.RemoveIfCompleted = true;
                newJob.NotifySettings    = new NotifySettings()
                {
                    NotifyWhenBuildIsComplete = true
                };
                newJob.JobUrl = String.Format("{0}/{1}", newJob.JobUrl, lastNumber);
                AddNewJob(newJob);
            });
            adder.Start();
        }