Example #1
0
        public async Task <JenkinsView> GetViewAsync(IJenkins jenkinsPlugin)
        {
            const string api = "api/json";

            using (var jenkinsRequest = new JenkinsRequest(jenkinsPlugin))
            {
                return(await jenkinsRequest.GetAsync <JenkinsView>(jenkinsPlugin, api).ConfigureAwait(false));
            }
        }
Example #2
0
        public async Task <JenkinsJob> GetJobAsync(IJenkins jenkinsPlugin)
        {
            const string api = "lastBuild/api/json?tree=result,building,executor[progress]";

            using (var jenkinsRequest = new JenkinsRequest(jenkinsPlugin))
            {
                return(await jenkinsRequest.GetAsync <JenkinsJob>(jenkinsPlugin, api).ConfigureAwait(false));
            }
        }
Example #3
0
        public async Task TriggerJobAsync(JenkinsJob_v1 jenkinsPlugin)
        {
            var api = jenkinsPlugin.IsParameterized ? BuildWithParametersApi(jenkinsPlugin) : "build?token=" + jenkinsPlugin.ApiToken;

            var crumb = jenkinsPlugin.CSRF ? await IssueCrumbAsync(jenkinsPlugin).ConfigureAwait(false) : null;

            using (var jenkinsRequest = new JenkinsRequest(jenkinsPlugin))
            {
                await jenkinsRequest.PostAsync(jenkinsPlugin, api, false, crumb).ConfigureAwait(false);
            }
        }
Example #4
0
        private async Task <JenkinsCrumb> IssueCrumbAsync(IJenkins jenkinsPlugin)
        {
            const string api = "crumbIssuer/api/json";

            try
            {
                using (var jenkinsRequest = new JenkinsRequest(jenkinsPlugin))
                {
                    var crumb = await jenkinsRequest.GetAsync <JenkinsCrumb>(jenkinsPlugin, api, true).ConfigureAwait(false);

                    if (!crumb.IsValid())
                    {
                        _logger.Info("Jenkins server did not return a valid crumb. Make sure your user name and API token are correct.");
                    }

                    return(crumb);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Jenkins: An error occurred while requesting crumb. Try to enable or disable CSRF in the properties window.", ex);
            }
        }