示例#1
0
        private async void button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                jenkinsJobRunner = new JenkinsJobRunner(jenkinsClient)
                {
                    BuildTimeout = 60 * 60
                };

                jenkinsJobRunner.StatusChanged += JenkinsJobRunner_StatusChanged;

                string jobName = JobCombo.SelectedValue.ToString();
                ListBinding.Add(new ListEntry {
                    Message = $"start {jobName}"
                });
                JenkinsBuildBase result = null;
                if (jobData[jobName].Count == 0)
                {
                    result = await jenkinsJobRunner.RunAsync(jobName);
                }
                else
                {
                    Dictionary <string, string> parameters = new Dictionary <string, string>();
                    foreach (var jobProperty in SelectedJob.JobProperties)
                    {
                        parameters[jobProperty.Key] = jobProperty.Value;
                    }
                    result = await jenkinsJobRunner.RunWithParametersAsync(jobName, parameters);
                }

                ListBinding.Add(new ListEntry {
                    Message = $"Duration { result.Duration } ms"
                });
                ListBinding.Add(new ListEntry {
                    Message = $"Result {result.Result}"
                });
            }
            catch (Exception ex)
            {
                var t = ex;
            }
        }
        /// <exception cref="JenkinsNetException"></exception>
        /// <exception cref="JenkinsJobBuildException"></exception>
        /// <exception cref="JenkinsJobGetBuildException"></exception>
        private async Task <JenkinsBuildBase> ProcessAsync(string jobName, JenkinsBuildResult buildResult, DateTime queueStartTime)
        {
            var queueItemNumber = buildResult.GetQueueItemNumber();

            if (!queueItemNumber.HasValue)
            {
                throw new JenkinsNetException("Queue-Item number not found!");
            }

            SetStatus(JenkinsJobStatus.Queued);

            int?buildNumber;

            while (true)
            {
                var queueItem = await client.Queue.GetItemAsync(queueItemNumber.Value);

                buildNumber = queueItem?.Executable?.Number;
                if (buildNumber.HasValue)
                {
                    break;
                }

                if (QueueTimeout > 0 && DateTime.Now.Subtract(queueStartTime).TotalSeconds > QueueTimeout)
                {
                    throw new JenkinsNetException("Timeout occurred while waiting for build to start!");
                }

                await Task.Delay(PollInterval);
            }

            SetStatus(JenkinsJobStatus.Building);
            var buildStartTime = DateTime.Now;

            textReader              = new ProgressiveTextReader(client, jobName, buildNumber.ToString());
            textReader.TextChanged += TextReader_TextChanged;

            JenkinsBuildBase buildItem = null;

            while (string.IsNullOrEmpty(buildItem?.Result))
            {
                buildItem = await client.Builds.GetAsync <JenkinsBuildBase>(jobName, buildNumber.Value.ToString());

                if (!string.IsNullOrEmpty(buildItem?.Result))
                {
                    break;
                }

                if (BuildTimeout > 0 && DateTime.Now.Subtract(buildStartTime).TotalSeconds > BuildTimeout)
                {
                    throw new JenkinsNetException("Timeout occurred while waiting for build to complete!");
                }

                if (MonitorConsoleOutput && !textReader.IsComplete)
                {
                    await textReader.UpdateAsync();
                }

                await Task.Delay(PollInterval);
            }

            while (MonitorConsoleOutput && !textReader.IsComplete)
            {
                await textReader.UpdateAsync();
            }

            SetStatus(JenkinsJobStatus.Complete);
            return(buildItem);
        }