3

I have Jenkins installed on my AWS EC2 server, on which the following are installed:

  • Maven Integration Plugin
  • Deploy to Container Plugin
  • Slack Notification Plugin
  • GitHub Integration Plugin

... and possibly a few others I cannot remember (because coding)...

I create new freestyle Project, go to its config, and do the following:

  • In General, check GitHub project, and enter the Project url
  • In Source Code Management, select Git and enter the Repository URL
  • In Build Triggers, check GitHub hook trigger for GITScm polling
  • In Build, I add build step "Invoke top-level Maven targets", and do the following:
    • Enter clean install in Goals
    • Enter relative path of my project's pom.xml in POM
  • In Post-build Actions, I do the following:
    • Archive the artifacts: enter image description here
    • Deploy war/ear to container: idk what our business port is but from others, it was 8085

On my attempt to build the (working) code, it fails, and I get this long stack of info on the console:

Started by user Mike Warren
Building in workspace /home/ec2-user/.jenkins/workspace/Project2
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/MikeWarren2014/171106-Project2-SHOULDi.git # timeout=10
Fetching upstream changes from https://github.com/MikeWarren2014/171106-Project2-SHOULDi.git
 > git --version # timeout=10
 > git fetch --tags --progress https://github.com/MikeWarren2014/171106-Project2-SHOULDi.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision d172c840db59d7aff020787e0b49f3741f57b555 (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f d172c840db59d7aff020787e0b49f3741f57b555
Commit message: "gamification finished"
 > git rev-list --no-walk d172c840db59d7aff020787e0b49f3741f57b555 # timeout=10
[Project2] $ mvn -f SHOULDi-back/pom.xml clean install
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building SHOULDi-back 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ SHOULDi-back ---
[INFO] Deleting /home/ec2-user/.jenkins/workspace/Project2/SHOULDi-back/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ SHOULDi-back ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ SHOULDi-back ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 49 source files to /home/ec2-user/.jenkins/workspace/Project2/SHOULDi-back/target/classes
[WARNING] /home/ec2-user/.jenkins/workspace/Project2/SHOULDi-back/src/main/java/com/zenith/DAO/UserDAO.java: Some input files use or override a deprecated API.
[WARNING] /home/ec2-user/.jenkins/workspace/Project2/SHOULDi-back/src/main/java/com/zenith/DAO/UserDAO.java: Recompile with -Xlint:deprecation for details.
[WARNING] /home/ec2-user/.jenkins/workspace/Project2/SHOULDi-back/src/main/java/com/zenith/DAO/UserDAO.java: Some input files use unchecked or unsafe operations.
[WARNING] /home/ec2-user/.jenkins/workspace/Project2/SHOULDi-back/src/main/java/com/zenith/DAO/UserDAO.java: Recompile with -Xlint:unchecked for details.
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ SHOULDi-back ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/ec2-user/.jenkins/workspace/Project2/SHOULDi-back/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ SHOULDi-back ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ SHOULDi-back ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-war-plugin:2.2:war (default-war) @ SHOULDi-back ---
[INFO] Packaging webapp
[INFO] Assembling webapp [SHOULDi-back] in [/home/ec2-user/.jenkins/workspace/Project2/SHOULDi-back/target/SHOULDi-back]
[INFO] Processing war project
[INFO] Copying webapp resources [/home/ec2-user/.jenkins/workspace/Project2/SHOULDi-back/src/main/webapp]
[INFO] Webapp assembled in [293 msecs]
[INFO] Building war: /home/ec2-user/.jenkins/workspace/Project2/SHOULDi-back/target/SHOULDi-back.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ SHOULDi-back ---
[INFO] Installing /home/ec2-user/.jenkins/workspace/Project2/SHOULDi-back/target/SHOULDi-back.war to /home/ec2-user/.m2/repository/com/zenith/SHOULDi-back/1.0-SNAPSHOT/SHOULDi-back-1.0-SNAPSHOT.war
[INFO] Installing /home/ec2-user/.jenkins/workspace/Project2/SHOULDi-back/pom.xml to /home/ec2-user/.m2/repository/com/zenith/SHOULDi-back/1.0-SNAPSHOT/SHOULDi-back-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.207 s
[INFO] Finished at: 2017-12-31T00:24:46+00:00
[INFO] Final Memory: 19M/48M
[INFO] ------------------------------------------------------------------------
Archiving artifacts
Deploying /home/ec2-user/.jenkins/workspace/Project2/SHOULDi-back/target/SHOULDi-back.war to container Tomcat 7.x Remote with context Project2
ERROR: Build step failed with exception
org.codehaus.cargo.container.ContainerException: Failed to redeploy [/home/ec2-user/.jenkins/workspace/Project2/SHOULDi-back/target/SHOULDi-back.war]
    at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:192)
    at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:77)
    at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:147)
    at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:117)
    at hudson.FilePath.act(FilePath.java:997)
    at hudson.FilePath.act(FilePath.java:975)
    at hudson.plugins.deploy.CargoContainerAdapter.redeploy(CargoContainerAdapter.java:114)
    at hudson.plugins.deploy.PasswordProtectedAdapterCargo.redeploy(PasswordProtectedAdapterCargo.java:93)
    at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:64)
    at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
    at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
    at hudson.model.Build$BuildExecution.post2(Build.java:186)
    at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
    at hudson.model.Run.execute(Run.java:1749)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:421)
Caused by: java.net.ConnectException: Connection timed out (Connection timed out)
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at java.net.Socket.connect(Socket.java:538)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:242)
    at sun.net.www.http.HttpClient.New(HttpClient.java:339)
    at sun.net.www.http.HttpClient.New(HttpClient.java:357)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1220)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:984)
    at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:561)
    at org.codehaus.cargo.container.tomcat.internal.TomcatManager.list(TomcatManager.java:876)
    at org.codehaus.cargo.container.tomcat.internal.TomcatManager.getStatus(TomcatManager.java:889)
    at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:173)
    ... 17 more
java.net.ConnectException: Connection timed out (Connection timed out)

How can I fix this?

My tomcat credentials, located in [tomcat directory]/conf/tomcat-users.xml, are as follows:

<tomcat-users>
        <role rolename="manager-gui"/>
        <role rolename="manager-script"/>
        <user username="tomcatgui" password="password" roles="manager-gui" />
        <user username="project2" password="Z3n1th0x47726f7570" roles="manager-script" />
</tomcat-users>
Mike Warren
  • 3,796
  • 5
  • 47
  • 99

5 Answers5

1

Since this is a connection time out,

  1. Check whether you restarted the tomcat instance after editing the tomcat-users.xml
  2. Check whether jenkins has access to tomcat instance.
  3. Whether the user credentials are correct
Ishan Thilina Somasiri
  • 1,179
  • 1
  • 12
  • 24
  • The error I see upon viewing `[tomcat directory]/logs/catalina.out`: `SEVERE: StandardServer.await: create[localhost:8005]: java.net.BindException: Address already in use (Bind failed) at java.net.PlainSocketImpl.socketBind(Native Method) at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387) at java.net.ServerSocket.bind(ServerSocket.java:375) at java.net.ServerSocket.(ServerSocket.java:237) at org.apache.catalina.core.StandardServer.await(StandardServer.java:444)` – Mike Warren Dec 31 '17 at 08:41
  • 1
    The port 8005 is used by someone else. So Tomcat cannot start. If you are on Linux, you can use `sudo netstat -tulpn | grep 8005` to check who is using the port. Stop that process (or change the tomcat start port - https://stackoverflow.com/questions/18415578/how-to-change-tomcat-port-number) and try again. – Ishan Thilina Somasiri Dec 31 '17 at 09:08
  • I get the following: `tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 4435/java ` – Mike Warren Dec 31 '17 at 09:33
  • I have no idea what that is. – Mike Warren Dec 31 '17 at 09:40
  • 4435 is the java process that uses the port 8005 – Ishan Thilina Somasiri Dec 31 '17 at 10:23
  • I just typed `ps aux` on the console, and got this: `ec2-user 4435 0.0 9.0 2280596 91996 ? Sl 00:21 0:34 /usr/java/jdk1.8.0_151/bin/java -Djava.util.logging.config.file=/home/ec2-user/apache-tomcat-7.0.82/con` – Mike Warren Dec 31 '17 at 17:37
  • I stopped that process, tried to rebuild, and still the same error – Mike Warren Dec 31 '17 at 18:24
1

For the same issue, setting port 8084 in server.xml and restarting the Apache worked for me. I replaced all occurrences of 8080 with 8084:

[root@ip-172-31-21-72 conf]# grep 8084 server.xml
     Define a non-SSL/TLS HTTP/1.1 Connector on port 8084
<Connector port="8084" protocol="HTTP/1.1"
           port="8084" protocol="HTTP/1.1"
Adam Michalik
  • 9,678
  • 13
  • 71
  • 102
Gauraw
  • 11
  • 1
0

comment tag Valve in context.xml files

<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />

there are multiple context.xml files in tomcat directory, update following context.xml files and restart tomcat service-

  • /apache-tomcat-8.5.41/webapps/manager/META-INF/context.xml
  • /apache-tomcat-8.5.41/webapps/host-manager/META-INF/context.xml
0

1.If you are using public IP address in AWS/Azure/any Server. if we stop and start server there might be a chance of change in Public IP which we used to Deploy Our Container. Instead we can use Elastic IP.

  1. To Redeploy Tomcat server if Public IP used then follow below steps Goto your Jenkins Dashboard: Manage Jenkins> configure>Post-build Actions --> Under Post build Actions change URL like Tomcat URL: http://ipa:8080

  2. Restart tomcat server. cd /opt/tomcat/bin/ && ./shutdown.sh cd /opt/tomcat/bin/ && ./startup.sh

  3. Open in Tomcat Manager Application.

-1

I GOT THE BUILD TO WORK!!!

What I did

In [tomcat directory]/conf/server.xml, I changed

 <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

to

<!-- my business port -->
<Connector port="8084" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

I then restart the Tomcat server, go to AWS EC2, only to realize there was no inbound rule for that business port! I created one, to accept connection from anywhere.

I then re-build the project. Upon trying to run the .war file, with

java -jar .jenkins/workspace/path/to/myProject.war

but get some issue about main (but this seems to be separate issue)...

Mike Warren
  • 3,796
  • 5
  • 47
  • 99