Exemplo n.º 1
0
        public void JenkinsJob_Create_SetConfig_GetConfig_Delete()
        {
            var job = new JenkinsJob(this.jenkinsConnection, "hudson.model.FreeStyleProject", "JenkinsJob_Create_Exists_Delete");

            Assert.IsTrue(job.Create());

            XmlDocument xmlDoc = new XmlDocument();

            // Load config
            xmlDoc.LoadXml(job.Config);
            // Doesn't have description element
            Assert.IsNull(xmlDoc.SelectSingleNode("./project/description"));

            // Add Description element
            XmlElement desc = xmlDoc.CreateElement("description");

            desc.InnerText = "hello";
            xmlDoc["project"].AppendChild(desc);

            // Save config
            job.Config = xmlDoc.OuterXml;

            // Load config
            xmlDoc.LoadXml(job.Config);

            // Has Description element
            Assert.IsNotNull(xmlDoc.SelectSingleNode("./project/description"));

            Assert.IsTrue(job.Delete());
        }
Exemplo n.º 2
0
        private void btn_add_new_job_Click(object sender, RoutedEventArgs e)
        {
            string jobName   = txt_new_job_name.Text;
            string jobUrl    = txt_new_job_url.Text;
            bool   temporary = check_temporary_job.IsChecked.Value;

            if (jobName == String.Empty)
            {
                jobName = jobUrl;
            }


            JenkinsJob newJob = new JenkinsJob(jobName, jobUrl, temporary, sentinel.LastIndex + 1);

            newJob.NotifySettings = new NotifySettings
            {
                NotifyWhenJobBecomesGreen = check_notify_green.IsChecked.Value,
                NotifyWhenJobBecomesRed   = check_notify_red.IsChecked.Value,
                NotifyWhenJobStateChanges = check_notify_status_changes.IsChecked.Value,
                NotifyWhenBuildIsComplete = check_notify_build_completed.IsChecked.Value
            };
            if (temporary)
            {
                newJob.RemoveIfCompleted = check_remove_done_job.IsChecked.Value;
            }

            sentinel.AddNewJob(newJob);
        }
Exemplo n.º 3
0
        public void DoNotifyWhenBuildIsCompleteTest1()
        {
            JenkinsJob currentJob = new JenkinsJob("name", "url", false, 0)
            {
                JobStatus = "FAILED",
                LastComletedBuildNumber = 249,
                Building       = true,
                NotifySettings = new NotifySettings()
                {
                    NotifyWhenBuildIsComplete = true
                }
            };


            JenkinsWorkflow NewStatus = new WorkflowJob()
            {
                lastBuild = new WorkflowRun()
                {
                    building = true, number = 251, result = null
                },
                lastCompletedBuild = new WorkflowRun()
                {
                    building = false, number = 250, result = "FAILED"
                },
            };

            bool expected = true;
            bool actual   = currentJob.DoNotify(NewStatus);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds single server project to the server projects list.
        /// </summary>
        /// <param name="parentList">The parent list.</param>
        /// <param name="jenkinsJobsItem">The new Jenkins Job Item.</param>
        /// <returns>The newly  created server projects tree item.</returns>
        private Project AddProject(IList <Project> parentList, JenkinsJob jenkinsJobsItem)
        {
            var newServerProject = new Project(jenkinsJobsItem.Url, jenkinsJobsItem.DisplayName ?? jenkinsJobsItem.Name, jenkinsJobsItem.Url, jenkinsJobsItem.FullName, jenkinsJobsItem.Description);

            parentList.Add(newServerProject);
            return(newServerProject);
        }
Exemplo n.º 5
0
 private JenkinsBuild GetRunningBuild(JenkinsJob job)
 {
     return(job.Builds
            .OrderBy(build => build.Number)
            .FirstOrDefault(build => (job.LastCompletedBuild == null || build.Number > job.LastCompletedBuild.Number) &&
                            (job.LastFailedBuild == null || build.Number > job.LastFailedBuild.Number)));
 }
 private void MergeUpdatedJenkinsJob(JenkinsJob refreshed, JenkinsJob original)
 {
     original.Builds    = refreshed.Builds;
     original.IsEnabled = refreshed.IsEnabled;
     original.IsQueued  = refreshed.IsQueued;
     original.Name      = refreshed.Name;
     original.QueueItem = refreshed.QueueItem;
 }
Exemplo n.º 7
0
 private void Init(JenkinsJob Job)
 {
     label_jobname.Content        = Job.JobName;
     label_jobname.ToolTip        = Job.JobUrl;
     label_jobstatus.Content      = Job.JobStatus;
     label_time.Content           = DateTime.Now.ToString("MM.dd. HH:mm:ss");
     border_background.Background = new SolidColorBrush(Job.JobStatusColor);
 }
Exemplo n.º 8
0
 private void ShowNotification(JenkinsJob UpdatedJob)
 {
     this.Dispatcher.Invoke(new Action(() =>
     {
         Notification notif = new Notification(UpdatedJob);
         notif.Show();
     }));
 }
Exemplo n.º 9
0
 public void JobRemoved(JenkinsJob Job)
 {
     this.Dispatcher.Invoke(new Action(() =>
     {
         list_jobs.Items.Remove(Job);
         RefreshJobList();
     }));
     persistor.PersistJobs(sentinel);
 }
Exemplo n.º 10
0
 public JobEditor(ListBox Jobs, Sentinel JenkinsSentinel, JenkinsJob Job)
 {
     InitializeComponent();
     this.persistor  = Persistor.GetInstance();
     this.jobs       = Jobs;
     this.sentinel   = JenkinsSentinel;
     this.currentJob = Job;
     LoadJobData(Job);
 }
Exemplo n.º 11
0
        private void img_open_job_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            int idx = list_jobs.SelectedIndex;

            if (idx != -1)
            {
                JenkinsJob job = list_jobs.Items[idx] as JenkinsJob;
                System.Diagnostics.Process.Start(job.JobUrl);
            }
        }
Exemplo n.º 12
0
 public void JobAdded(JenkinsJob Job)
 {
     this.Dispatcher.Invoke(new Action(() =>
     {
         list_jobs.Items.Add(Job);
         RefreshJobList();
     }));
     persistor.PersistJobs(sentinel);
     MessageBox.Show("New job added");
 }
Exemplo n.º 13
0
        private void RemoveJob()
        {
            int idx = list_jobs.SelectedIndex;

            if (idx != -1)
            {
                JenkinsJob job = list_jobs.Items[idx] as JenkinsJob;
                sentinel.RemoveJob(job);
            }
        }
Exemplo n.º 14
0
        private int GetLastRanBuildNumber(JenkinsJob job)
        {
            var lastBuild = job.Builds
                            .Where(b => job.LastCompletedBuild != null && b.Number == job.LastCompletedBuild.Number ||
                                   job.LastFailedBuild != null && b.Number == job.LastFailedBuild.Number)
                            .OrderByDescending(b => b.Number)
                            .FirstOrDefault();

            return(lastBuild != null ? lastBuild.Number : 0);
        }
Exemplo n.º 15
0
        private void img_refresh_job_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            int idx = list_jobs.SelectedIndex;

            if (idx != -1)
            {
                JenkinsJob job = list_jobs.Items[idx] as JenkinsJob;
                sentinel.UpdateJob(job);
            }
        }
Exemplo n.º 16
0
        public void InvokeRunJobAsyncShouldCallPostDataAsync()
        {
            var job = new JenkinsJob {
                Url = "MonJobUrl"
            };

            this.defaultClient.RunJobAsync(job.BuildRestUrl).Wait();

            this.restManager.Verify(m => m.PostDataAsync(It.Is <string>(u => string.Equals(u, job.BuildRestUrl, StringComparison.OrdinalIgnoreCase)), It.Is <string>(d => string.Equals(d, string.Empty))), Times.Once);
        }
 private void ShowWebsite(JenkinsJob j)
 {
     try
     {
         Process.Start(j.Url);
     }
     catch (Exception ex)
     {
         Logger.Log(ex);
     }
 }
        private static Uri CreateCancelBuildUri(JenkinsJob job)
        {
            var serverUri = new Uri(job.Url);

            if (job.LatestBuild != null && job.LatestBuild.IsBuilding)
            {
                return(new Uri(serverUri, job.LatestBuild.Number + "/stop"));
            }

            return(null);
        }
Exemplo n.º 19
0
        private async Task <JenkinsJobViewModel> CreateJenkinsJobViewModel(JenkinsJob job)
        {
            var jobUpdated = await this.jenkinsClient.GetJobAsync(job.RestUrl);

            var lastBuildNumber = this.GetLastRanBuildNumber(jobUpdated);
            var buildRunning    = this.GetBuildRunningState(jobUpdated);
            var startBuildUrl   = jobUpdated.BuildRestUrl;
            var stopBuildUrl    = buildRunning ? this.GetRunningBuild(jobUpdated).StopRestUrl : string.Empty;

            return(new JenkinsJobViewModel(job.DisplayName, this.ConvertJenkinsJobToJob(job.Status), job.Url, lastBuildNumber, new RunBuildCommand(this.jenkinsClient, startBuildUrl), new StopBuildCommand(this.jenkinsClient, stopBuildUrl), buildRunning));
        }
Exemplo n.º 20
0
        private void job_name_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            int idx = list_jobs.SelectedIndex;

            if (idx != -1)
            {
                JenkinsJob job    = list_jobs.Items[idx] as JenkinsJob;
                JobEditor  editor = new JobEditor(list_jobs, sentinel, job);
                editor.Show();
            }
        }
Exemplo n.º 21
0
        private static Uri CreateCancelBuildUri(JenkinsJob job)
        {
            var serverUri = new Uri(job.Url);

            if (job.LatestBuild != null && job.LatestBuild.IsBuilding)
            {
                // http://vmsobuild03:8080/job/Bronkhorst.BHTInstruments6%20Development/870/stop
                return(new Uri(serverUri, job.LatestBuild.Number + "/stop"));
            }

            return(null);
        }
        private async void BuildJobWithDefaultParameters(JenkinsJob job)
        {
            try
            {
                await JenkinsJobManager.BuildJobWithDefaultParameters(job, SelectedJenkinsServer.Url);

                ForceReload(false);
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }
        private async void BuildJob(JenkinsJob j)
        {
            try
            {
                await BuildJob(j.Url, SelectedJenkinsServer.Url);

                ForceReload(false);
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }
Exemplo n.º 24
0
        private void MoveSelectedJobDown()
        {
            int idx = list_jobs.SelectedIndex;

            if (idx != -1)
            {
                JenkinsJob job = list_jobs.Items[idx] as JenkinsJob;
                if (sentinel.MoveJobIndexDown(job))
                {
                    persistor.PersistJobs(sentinel);
                    SortJobList();
                }
            }
        }
Exemplo n.º 25
0
 private void LoadJobData(JenkinsJob Job)
 {
     txt_job_name.Text                      = Job.JobName;
     txt_job_url.Text                       = Job.JobUrl;
     check_notify_green.IsChecked           = Job.NotifySettings.NotifyWhenJobBecomesGreen;
     check_notify_red.IsChecked             = Job.NotifySettings.NotifyWhenJobBecomesRed;
     check_notify_status_changes.IsChecked  = Job.NotifySettings.NotifyWhenJobStateChanges;
     check_notify_build_completed.IsChecked = Job.NotifySettings.NotifyWhenBuildIsComplete;
     check_temporary_job.IsChecked          = Job.IsTemporary;
     check_remove_done_job.IsChecked        = Job.RemoveIfCompleted;
     check_remove_done_job.IsEnabled        = check_temporary_job.IsChecked.Value;
     txt_job_status.Content                 = Job.JobStatus;
     job_state_color.Fill                   = new SolidColorBrush(Job.JobStatusColor);
 }
Exemplo n.º 26
0
        public void JenkinsJob_Null_Not_Equal()
        {
            // Arrange
            JenkinsJob origin;
            JenkinsJob other;

            // Act
            origin = new JenkinsJob(this.jenkinsConnection, "hudson.model.FreeStyleProject", "SameJob");
            other  = null;

            // Assert
            Assert.AreNotEqual(origin, other);
            Assert.IsFalse(origin.Equals(other));
        }
Exemplo n.º 27
0
        public void JenkinsJob_Duplicate_Is_Equal()
        {
            // Arrange
            JenkinsJob origin;
            JenkinsJob other;

            // Act
            origin = new JenkinsJob(this.jenkinsConnection, "hudson.model.FreeStyleProject", "SameJob");
            other  = new JenkinsJob(this.jenkinsConnection, "hudson.model.FreeStyleProject", "SameJob");

            // Assert
            Assert.AreEqual(origin, other);
            Assert.IsTrue(origin.Equals(other));
            Assert.AreEqual(origin.GetHashCode(), other.GetHashCode());
        }
Exemplo n.º 28
0
        public void MoveJobIndexUpTest()
        {
            sentinel.Jobs = new System.Collections.Generic.List <JenkinsJob>()
            {
                new JenkinsJob("j", "u1", false, 0),
                new JenkinsJob("j", "u2", false, 1),
                new JenkinsJob("j", "u3", false, 2),
                new JenkinsJob("j", "u4", false, 3),
            };
            JenkinsJob Job = sentinel.Jobs[1];

            sentinel.MoveJobIndexUp(Job);
            Assert.AreEqual(sentinel.Jobs[0].Index, 1);
            Assert.AreEqual(sentinel.Jobs[1].Index, 0);
        }
Exemplo n.º 29
0
        public void JenkinsJob_Create_Exists_Delete()
        {
            var job = new JenkinsJob(this.jenkinsConnection, "hudson.model.FreeStyleProject", "JenkinsJob_Create_Exists_Delete");

            Assert.IsFalse(job.Exists);

            Assert.IsTrue(job.Create());
            Assert.IsTrue(job.Create());
            Assert.IsFalse(job.Create(true));

            Assert.IsTrue(job.Exists);

            Assert.IsTrue(job.Delete());
            Assert.IsTrue(job.Delete());
            Assert.IsFalse(job.Delete(true));
        }
        public async static Task CancelBuild(JenkinsJob job, string jenkinsServerUrl)
        {
            if (job == null)
            {
                throw new ArgumentNullException("job");
            }

            Uri cancelBuildUri = CreateCancelBuildUri(job);

            if (cancelBuildUri != null)
            {
                using (WebClient client = JenkinsDataLoader.CreateJenkinsWebClient(jenkinsServerUrl))
                {
                    byte[] response = await client.UploadValuesTaskAsync(cancelBuildUri, new NameValueCollection());
                }
            }
        }