Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-70130

Can not execute build job from remote java program

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Blocker Blocker
    • jenkinslint-plugin
    • None
    • windows /linux /java

      I m executing a java programme to run a jenkins job ( name "terraform-example" ) which runs on the same machine it works fine. Here is the code 

      import java.net.URI;

      import com.offbytwo.jenkins.JenkinsServer;
      import com.offbytwo.jenkins.model.BuildWithDetails;

      public class Main {
          public static void main(String[] args) {

              try

      {             JenkinsServer jenkinsServer = new JenkinsServer(new URI("http://localhost:8080/"),"admin","apitoken");          //            JenkinsServer jenkinsServer = new JenkinsServer( URI.create("http://192.168.1.207:8080/"),"admin","apitoken");             JenkinsTriggerHelper triggerHelper = new JenkinsTriggerHelper(jenkinsServer);             BuildWithDetails details = triggerHelper.triggerJobAndWaitUntilFinished("terraform-example");                      if (details!=null)                 System.out.println("LOGS " + details.getConsoleOutputText());             else                 System.out.println("details not found " );                      }

      catch (Exception e)

      {             e.printStackTrace();         }

          }    
      }

       

      Out put

       

      LOGS Started by user Sudipta Ghosh
      [Pipeline] Start of Pipeline
      [Pipeline] node
      Running on Jenkins in C:\Users\SGHOSH43\.jenkins\workspace\terraform-example
      [Pipeline] {
      [Pipeline] stage
      [Pipeline]

      { (Pre Build Cleanup) [Pipeline] echo Workspace cleaning operation will start now. [Pipeline] cleanWs [WS-CLEANUP] Deleting project workspace... [WS-CLEANUP] Deferred wipeout is used... [WS-CLEANUP] done [Pipeline] echo Workspace cleaned [Pipeline] }

      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline]

      { (Execute Maven to Build Application) [Pipeline] echo MAVEN_HOME = C:\apache-maven-3.8.6 [Pipeline] echo JAVA_HOME = C:\Program Files\Eclipse Foundation\jdk-11.0.12.7-hotspot [Pipeline] }

      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: SUCCESS

       

      when I point to a remote jenkins server it throws exception. though port is open and web url can be accessed from remote

       

       

      org.apache.http.conn.HttpHostConnectException: Connect to 192.168.1.207:8080 [/192.168.1.207] failed: Connection timed out: connect
          at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:156)
          at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:376)
          at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
          at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
          at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
          at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
          at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
          at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
          at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
          at com.offbytwo.jenkins.client.JenkinsHttpClient.get(JenkinsHttpClient.java:149)
          at com.offbytwo.jenkins.JenkinsServer.getJob(JenkinsServer.java:283)
          at com.offbytwo.jenkins.JenkinsServer.getJob(JenkinsServer.java:270)
          at com.capgemini.terraform.parser.JenkinsTriggerHelper.triggerJobAndWaitUntilFinished(JenkinsTriggerHelper.java:154)
          at com.capgemini.terraform.parser.JenkinsTriggerHelper.triggerJobAndWaitUntilFinished(JenkinsTriggerHelper.java:53)
          at com.capgemini.terraform.parser.Main.main(Main.java:17)
      Caused by: java.net.ConnectException: Connection timed out: connect
          at java.base/java.net.PlainSocketImpl.connect0(Native Method)
          at java.base/java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:101)
          at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
          at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
          at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
          at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
          at java.base/java.net.Socket.connect(Socket.java:609)
          at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)
          at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
          ... 14 more

       

            v2v Victor Martinez
            sudipta2006 sudipta
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: