Ejemplo n.º 1
0
        public JenkinsClient(JenkinsConfig jenkinsConfig)
        {
            if (jenkinsConfig == null)
            {
                throw new ArgumentNullException(nameof(jenkinsConfig));
            }

            this.jenkinsConfig = jenkinsConfig;

            if (jenkinsConfig.Username.HasValue && jenkinsConfig.ApiKey.HasValue)
            {
                var byteArray = Encoding.ASCII.GetBytes(jenkinsConfig.Username.Value + ':' + jenkinsConfig.ApiKey.Value);
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Add the Jenkins client to the service collection as a singleton.
 /// </summary>
 /// <param name="services">The service collection.</param>
 /// <param name="config">The jenkins configuration.</param>
 /// <returns>The passed service collection.</returns>
 public static IServiceCollection AddJenkins(this IServiceCollection services, JenkinsConfig config)
 {
     return(services.AddSingleton <IJenkinsClient>(new JenkinsClient(config)));
 }