ERROR: Build step failed with exception org.codehaus.cargo.container.ContainerException: Failed to redeploy

20,695

Solution 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"

Solution 2

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
Share:
20,695
Mike Warren
Author by

Mike Warren

I am a software developer in test, with an affinity for other things such as math.

Updated on April 02, 2021

Comments

  • Mike Warren
    Mike Warren about 3 years

    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>
    
    • Ishan Thilina Somasiri
      Ishan Thilina Somasiri over 6 years
      Are your tomcat details correct? Jenkins can't deploy the WAR to tomcat it seems.
    • Mike Warren
      Mike Warren over 6 years
      I'm about to put the credentials of tomcat/conf/tomcat-users.xml here.
    • Mike Warren
      Mike Warren over 6 years
      I didn't know what to put for context path...
    • Ishan Thilina Somasiri
      Ishan Thilina Somasiri over 6 years
      The context path is the context path part of the URL under which your application will be published in Tomcat.
    • matbrgz
      matbrgz over 6 years
      java.net.ConnectException: Connection timed out (Connection timed out) indicate a firewall problem.
  • Mike Warren
    Mike Warren over 6 years
    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(AbstractPlainSocketImp‌​l.java:387) at java.net.ServerSocket.bind(ServerSocket.java:375) at java.net.ServerSocket.<init>(ServerSocket.java:237) at org.apache.catalina.core.StandardServer.await(StandardServer‌​.java:444)
  • Ishan Thilina Somasiri
    Ishan Thilina Somasiri over 6 years
    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 - stackoverflow.com/questions/18415578/…) and try again.
  • Mike Warren
    Mike Warren over 6 years
    I get the following: tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 4435/java
  • Mike Warren
    Mike Warren over 6 years
    I have no idea what that is.
  • Ishan Thilina Somasiri
    Ishan Thilina Somasiri over 6 years
    4435 is the java process that uses the port 8005
  • Mike Warren
    Mike Warren over 6 years
    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
    Mike Warren over 6 years
    I stopped that process, tried to rebuild, and still the same error
  • Sasha Bond
    Sasha Bond almost 5 years
    <Context antiResourceLocking="false" privileged="true" docBase="${catalina.base}/webapps/manager"> <!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="172\.16\.40\.41|127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:‌​0:1" /> --> <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean‌​|Integer|Long|Number‌​|String)|org\.apache‌​\.catalina\.filters\‌​.CsrfPreventionFilte‌​r\$LruCache(?:\$1)?|‌​java\.util\.(?:Linke‌​d)?HashMap"/> </Context>
  • M. Rostami
    M. Rostami almost 4 years
    There is no Valve tag in my docker instance.