You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jenkins部署150MB WAR包至Tomcat 9耗时过长问题求助

Troubleshooting Jenkins-Tomcat Deployment Issues: Slow Uploads & Manual Cleanup

Hey there, sorry to hear you're stuck with these frustrating deployment hiccups—let's walk through some actionable fixes and ideas to smooth out your pipeline.

1. Fixing the "WAR Uploaded but Jenkins Stuck Waiting" Issue

This is almost always tied to either Tomcat's processing bottlenecks or timeout mismatches between Jenkins and Tomcat. Here's what to check first:

  • Verify Tomcat Manager's timeout & resource settings
    Beyond the multipart-config you already adjusted, check Tomcat's server.xml for the Connector handling Manager requests. Increase timeouts to give Tomcat enough time to process the large WAR:

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="300000" <!-- 5 minutes, up from default 20s -->
               keepAliveTimeout="60000"
               maxThreads="200" />
    

    Also, bump up Tomcat's heap memory via CATALINA_OPTS (in bin/setenv.sh or setenv.bat) to handle large WAR unpacking and app initialization:

    export CATALINA_OPTS="-Xmx2g -Xms1g -XX:MaxMetaspaceSize=512m"
    
  • Check Jenkins Deployment Plugin Timeouts
    If you're using the "Deploy to container" plugin, double-check its timeout settings. By default, it might only wait 120 seconds—way too short for a 140MB WAR's initialization. Increase this to 300+ seconds in the plugin's configuration for your deployment step.

  • Inspect Tomcat Logs in Real-Time
    When Jenkins gets stuck, tail catalina.out and localhost.log on your Tomcat server. You might see that Tomcat is still unpacking the WAR, initializing Spring beans, or running database migrations—all of which take time for large apps. If this is the case, optimizing your app's startup time (e.g., lazy-loading non-critical components) will help long-term.

  • Validate Multipart Config is Active
    Make sure you edited the correct web.xml (it should be TOMCAT_HOME/webapps/manager/WEB-INF/web.xml) and restarted Tomcat. Test a manual upload via curl to rule out Jenkins-specific issues:

    curl -u your-tomcat-username:password -T your-app.war http://tomcat-host:8080/manager/text/deploy?path=/your-app&update=true
    

    If this succeeds without hanging, the problem is likely in Jenkins' plugin configuration.

2. Eliminating Manual Cleanup & Restarts

The need to manually delete old WARs and restart Tomcat usually means your deployment step isn't handling app replacement properly:

  • Enable Auto-Undeploy in Jenkins
    In your "Deploy to container" step, check the box labeled Undeploy before deploy—this tells Tomcat to remove the existing app before pushing the new WAR. Alternatively, add the update=true parameter to your deployment URL (like the curl example above) to trigger an in-place update.

  • Add an Automated Tomcat Restart Step
    If your app requires a restart after deployment (common with legacy apps), add an SSH build step to Jenkins to run a graceful restart script on the Tomcat server:

    # Gracefully shut down Tomcat
    /opt/tomcat/bin/shutdown.sh
    # Wait for processes to exit (adjust sleep time as needed)
    sleep 15
    # Kill any lingering Tomcat processes
    pkill -f tomcat
    # Start Tomcat back up
    /opt/tomcat/bin/startup.sh
    

    For extra reliability, add a step to delete the old app directory from webapps before deploying, to avoid leftover files causing conflicts.

  • Check for Locked Files
    Sometimes Tomcat holds locks on JARs or config files from the old app, preventing replacement. If you still see issues after auto-undeploy, add a step to stop Tomcat before deploying, push the WAR, then start it back up. This ensures no files are in use during the update.

3. Optimizing Overall Deployment Speed

To cut down on total pipeline time, try these tweaks:

  • Parallelize Build & Analysis
    If you're using Jenkins Pipeline, run SonarQube analysis and Jacoco tests in parallel with your build (if they don't depend on each other). Example snippet:

    stage('Build & Test') {
      parallel {
        stage('Build') {
          steps { sh 'mvn clean package' }
        }
        stage('SonarQube Analysis') {
          steps { sh 'mvn sonar:sonar' }
        }
      }
    }
    
  • Cache Dependencies
    Use Jenkins' built-in dependency caching (for Maven/Gradle) or plugins like Pipeline Cache to avoid re-downloading dependencies every build. This can shave minutes off your build time.

  • Incremental Builds
    Configure Jenkins to only build modules that have changed (if you're working with a multi-module project). Plugins like Incremental Build can help with this.


内容的提问来源于stack exchange,提问作者Aurelius Baier

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 15:17:46