Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Minor
    • Resolution: Won't Do
    • Component/s: pipeline
    • Labels:
      None
    • Environment:
      centos 7 master,
      openjdk8,
      jenkins 1.631
      workflow plugin 1.10
    • Similar Issues:

      Description

      I have a script I can run via terminal, and via the envinject plugin

      import javax.net.ssl.HostnameVerifier
      import javax.net.ssl.HttpsURLConnection
      import javax.net.ssl.SSLContext
      import javax.net.ssl.TrustManager
      import javax.net.ssl.X509TrustManager
      
      def nullTrustManager = [
          checkClientTrusted: { chain, authType ->  },
          checkServerTrusted: { chain, authType ->  },
          getAcceptedIssuers: { null }
      ]
      
      def nullHostnameVerifier = [
          verify: { hostname, session -> true }
      ]
      
      SSLContext sc = SSLContext.getInstance("SSL")
      sc.init(null, [nullTrustManager as X509TrustManager] as TrustManager[], null)
      HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory())
      HttpsURLConnection.setDefaultHostnameVerifier(nullHostnameVerifier as HostnameVerifier)
      
      URL url = new URL('<my svn https url>');
      URLConnection conn = url.openConnection();
      String basicAuth = "Basic " + <my base 64 encoded user:pass> ;
      conn.setRequestProperty ("Authorization", basicAuth);
      
      svnPageContents = conn.content.text
      regexGroup = (svnPageContents =~ /svn - Revision (\d+):/)
      printf ("found: ${regexGroup[1][1]}")
      

      This just connects to svn to get the latest rev number, on a svn server with a self signed cert. On the console and in envinject this works fine. In the workflow plugin groovy script it exceptions out

      java.lang.NullPointerException: Cannot get property 'text' on null object
      

      So my openConnection is returning null. I don't know why, but it's easy to reproduce

        Attachments

          Issue Links

            Activity

            Hide
            jglick Jesse Glick added a comment -

            No idea offhand. If you have a way of reproducing from scratch using a self-contained test case, reopen with details.

            Show
            jglick Jesse Glick added a comment - No idea offhand. If you have a way of reproducing from scratch using a self-contained test case, reopen with details.
            Hide
            aflat aflat added a comment - - edited

            Create a new workflow, paste the script below in. Replace the PASTEYOURBASE64USR:PASSHERE with your base64 encoded user:pass for this jira instance. Run your workflow
            --------------------------------------------------------

            
            import javax.net.ssl.HostnameVerifier
            import javax.net.ssl.HttpsURLConnection
            import javax.net.ssl.SSLContext
            import javax.net.ssl.TrustManager
            import javax.net.ssl.X509TrustManager
            
            def nullTrustManager = [
                checkClientTrusted: { chain, authType ->  },
                checkServerTrusted: { chain, authType ->  },
                getAcceptedIssuers: { null }
            ]
            
            def nullHostnameVerifier = [
                verify: { hostname, session -> true }
            ]
            
            SSLContext sc = SSLContext.getInstance("SSL")
            sc.init(null, [nullTrustManager as X509TrustManager] as TrustManager[], null)
            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory())
            HttpsURLConnection.setDefaultHostnameVerifier(nullHostnameVerifier as HostnameVerifier)
            
            URL url = new URL('https://issues.jenkins-ci.org/browse/JENKINS-30978');
            URLConnection uc = url.openConnection();
            String basicAuth = "Basic PASTEYOURBASE64USR:PASSHERE" ;
            uc.setRequestProperty ("Authorization", basicAuth);
            
            svnPageContents = uc.content.text
            print svnPageContents
            
            Show
            aflat aflat added a comment - - edited Create a new workflow, paste the script below in. Replace the PASTEYOURBASE64USR:PASSHERE with your base64 encoded user:pass for this jira instance. Run your workflow -------------------------------------------------------- import javax.net.ssl.HostnameVerifier import javax.net.ssl.HttpsURLConnection import javax.net.ssl.SSLContext import javax.net.ssl.TrustManager import javax.net.ssl.X509TrustManager def nullTrustManager = [ checkClientTrusted: { chain, authType -> }, checkServerTrusted: { chain, authType -> }, getAcceptedIssuers: { null } ] def nullHostnameVerifier = [ verify: { hostname, session -> true } ] SSLContext sc = SSLContext.getInstance( "SSL" ) sc.init( null , [nullTrustManager as X509TrustManager] as TrustManager[], null ) HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()) HttpsURLConnection.setDefaultHostnameVerifier(nullHostnameVerifier as HostnameVerifier) URL url = new URL( 'https: //issues.jenkins-ci.org/browse/JENKINS-30978' ); URLConnection uc = url.openConnection(); String basicAuth = "Basic PASTEYOURBASE64USR:PASSHERE" ; uc.setRequestProperty ( "Authorization" , basicAuth); svnPageContents = uc.content.text print svnPageContents
            Hide
            jglick Jesse Glick added a comment -

            Possibly some failure to interpret the more exotic points of Groovy syntax, no idea.

            In general you should not be writing code like this in a Workflow script. Use an external process to make network connections, perform significant I/O, or use any complex Java or Groovy libraries. The flow script is intended only for overall orchestration and simple scripting. It is not possible or wise to run arbitrary Groovy code.

            Show
            jglick Jesse Glick added a comment - Possibly some failure to interpret the more exotic points of Groovy syntax, no idea. In general you should not be writing code like this in a Workflow script. Use an external process to make network connections, perform significant I/O, or use any complex Java or Groovy libraries. The flow script is intended only for overall orchestration and simple scripting. It is not possible or wise to run arbitrary Groovy code.
            Hide
            aflat aflat added a comment -

            Agreed about the groovy code. It's me converting a multi job build to a workflow build, so I'm converting slowly.

            After more research, I found the whole workflow process hangs when trying to request the content, I can't even abort the build. Instead of

            svnPageContents = uc.content.text

            I just do a

            print uc.content

            and the whole workflow job hangs. No output is printed. If I click abort, it receives the abort, but doesn't really abort the job. It looks like a timeout happens after a while.

            Show
            aflat aflat added a comment - Agreed about the groovy code. It's me converting a multi job build to a workflow build, so I'm converting slowly. After more research, I found the whole workflow process hangs when trying to request the content, I can't even abort the build. Instead of svnPageContents = uc.content.text I just do a print uc.content and the whole workflow job hangs. No output is printed. If I click abort, it receives the abort, but doesn't really abort the job. It looks like a timeout happens after a while.
            Hide
            jglick Jesse Glick added a comment -

            Right, blocking methods should never be called from a flow script. Output and event handling only occurs at method call boundaries. Using an external process solves such issues.

            Show
            jglick Jesse Glick added a comment - Right, blocking methods should never be called from a flow script. Output and event handling only occurs at method call boundaries. Using an external process solves such issues.
            Hide
            jglick Jesse Glick added a comment -

            See JENKINS-32986 regarding the abort.

            Show
            jglick Jesse Glick added a comment - See JENKINS-32986 regarding the abort.

              People

              • Assignee:
                jglick Jesse Glick
                Reporter:
                aflat aflat
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: