Repository: jenkinsci/jira-plugin
Issue: "No Proxy Host"-List is not used

<!--
Never report security issues on GitHub or other public channels (Gitter/Twitter/etc.), follow the instruction from [Jenkins Security](https://jenkins.io/security/).
-->

### Your checklist for this issue

🚨 Please review the [guidelines for contributing](../blob/master/CONTRIBUTING.md) to this repository.

- [x] Jenkins version ==> 2.346.1

- [x] Plugin version ==> 3.7.1

- [x] OS ==>  Red Hat Enterprise Linux Server 7.9 (Maipo)

<!--
Put an `x` into the [ ] to show you have filled the information below
Describe your issue below
-->

### Reproduction steps

- Add a Proxy
- Add the Jira-Server to the "No Proxy Host"-List
- Use the Plugin (we use it to read Versions)

### Results

Expected result:

Jira is accesses without the Proxy, since the Jira-Server is on the "No Proxy Host"-List

Actual result:

The Proxy is used to connect to Jira, our Proxy can't resolve the Jira server, and that cause an Error:
See this log:

- http://webproxy.mycompany.example.com:8080 is the Proxy server
- http://jira.otherdomain.example.com:8080 is the Jira Server, and jira.otherdomain.example.com is on the "No Proxy Host"-List

```
Jul 20, 2022 2:02:48 PM FINE org.apache.http.impl.conn.PoolingHttpClientConnectionManager releaseConnection

Connection released: [id: 10088571][route: {}->http://webproxy.mycompany.example.com:8080->http://jira.otherdomain.example.com:8080][total available: 1; route allocated: 1 of 100; total allocated: 1 of 200]

Jul 20, 2022 2:02:48 PM WARNING hudson.plugins.jira.JiraRestService getVersions

Jira REST client get versions error. cause: status code: 502, reason phrase: notresolvable
org.apache.http.client.HttpResponseException: status code: 502, reason phrase: notresolvable
	at org.apache.http.impl.client.AbstractResponseHandler.handleResponse(AbstractResponseHandler.java:70)
	at org.apache.http.client.fluent.Response.handleResponse(Response.java:90)
	at org.apache.http.client.fluent.Response.returnContent(Response.java:97)
	at hudson.plugins.jira.JiraRestService.getVersions(JiraRestService.java:232)
	at hudson.plugins.jira.JiraSession.getVersions(JiraSession.java:147)
	at hudson.plugins.jira.versionparameter.JiraVersionParameterDefinition.getVersions(JiraVersionParameterDefinition.java:69)
	at jdk.internal.reflect.GeneratedMethodAccessor1364.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
```

Relates to https://github.com/jenkinsci/jira-plugin/issues/385 where the proxy was first used


Changed files:
src/main/java/hudson/plugins/jira/JiraRestService.java, src/test/java/hudson/plugins/jira/JiraRestServiceProxyTest.java

diff --git a/src/main/java/hudson/plugins/jira/JiraRestService.java b/src/main/java/hudson/plugins/jira/JiraRestService.java
index 11e8d23..592fe7a 100644
--- a/src/main/java/hudson/plugins/jira/JiraRestService.java
+++ b/src/main/java/hudson/plugins/jira/JiraRestService.java
@@ -445,7 +445,13 @@ public class JiraRestService {
         ProxyConfiguration proxyConfiguration = Jenkins.get().proxy;
         if ( proxyConfiguration != null ) {
             final HttpHost proxyHost = new HttpHost( proxyConfiguration.name, proxyConfiguration.port );
-            request.viaProxy(proxyHost);
+
+            boolean shouldByPassProxy = proxyConfiguration.getNoProxyHostPatterns().stream().anyMatch(
+                    it -> it.matcher(uri.getHost()).matches()
+            );
+
+            if(!shouldByPassProxy)
+                request.viaProxy(proxyHost);
         }
 
         return request
diff --git a/src/test/java/hudson/plugins/jira/JiraRestServiceProxyTest.java b/src/test/java/hudson/plugins/jira/JiraRestServiceProxyTest.java
index fdbcab7..88564d9 100644
--- a/src/test/java/hudson/plugins/jira/JiraRestServiceProxyTest.java
+++ b/src/test/java/hudson/plugins/jira/JiraRestServiceProxyTest.java
@@ -63,6 +63,18 @@ public class JiraRestServiceProxyTest {
     assertEquals(localPort, proxyHost.getPort());
   }
 
+  @Test
+  public void withProxyAndNoProxyHosts() throws Exception {
+    int localPort = connector.getLocalPort();
+    Jenkins.get().proxy = new ProxyConfiguration("localhost", localPort);
+    Jenkins.get().proxy.setNoProxyHost("example.com|google.com");
+
+
+    assertNull(getProxyObjectFromRequest());
+
+  }
+
+
   @Test
   public void withoutProxy() throws Exception {
     assertNull(getProxyObjectFromRequest());
@@ -76,7 +88,7 @@ public class JiraRestServiceProxyTest {
     Method m = service.getClass().getDeclaredMethod("buildGetRequest", URI.class);
     m.setAccessible(true);
 
-    Request buildGetRequestValue = (Request) m.invoke(service, URI.create(""));
+    Request buildGetRequestValue = (Request) m.invoke(service, JIRA_URI);
 
     assertNotNull(buildGetRequestValue);