使用Jenkins上传WAR文件至Tomcat,无法找到manager账号密码求助
Hey there! Let's work through why you can't locate or use the Tomcat Manager's username and password to deploy your WAR file via Jenkins. Here are the critical configurations and steps you might have overlooked:
1. Verify Tomcat's User Configuration File
First, check the core user setup file for Tomcat: TOMCAT_HOME/conf/tomcat-users.xml. This is where you define users with access to the Manager app.
You need to add a user with both manager-gui (for web interface access) and manager-script (for API-based deployments like Jenkins) roles. Add this snippet inside the <tomcat-users> tag:
<user username="jenkins-deployer" password="your-strong-password" roles="manager-gui,manager-script"/>
Note: Replace jenkins-deployer and your-strong-password with your preferred credentials.
2. Adjust Manager App Access Restrictions
By default, Tomcat restricts Manager access to local IPs. If Jenkins is running on a different server (or even the same machine but via a non-local endpoint), you need to update the context config:
Go to TOMCAT_HOME/webapps/manager/META-INF/context.xml and modify the RemoteAddrValve section. For example:
- If Jenkins is on the same server, you can keep the default but ensure your Jenkins process is accessing via localhost.
- If Jenkins is on another server, add its IP to the
allowlist:
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.168.1.100"/>
Replace 192.168.1.100 with your Jenkins server's actual IP. You can also temporarily comment out this Valve to test if access restrictions are the issue.
3. Restart Tomcat After Configuration Changes
Any edits to Tomcat's config files won't take effect until you restart the server. Run these commands (adjust for your OS):
- Linux/macOS:
$ TOMCAT_HOME/bin/shutdown.sh $ TOMCAT_HOME/bin/startup.sh - Windows:
TOMCAT_HOME\bin\shutdown.bat TOMCAT_HOME\bin\startup.bat
4. Validate Jenkins Credential Setup
Once Tomcat is configured correctly, double-check your Jenkins deployment configuration:
- Ensure you've created a Username with password credential in Jenkins using the exact username and password you defined in
tomcat-users.xml. - In your Jenkins job's deployment step (e.g., "Deploy war/ear to a container"), select this credential and confirm the Tomcat Manager URL is correct (usually
http://<tomcat-server>:<port>/manager/textfor script-based access). - Test the connection directly from Jenkins to rule out typos or credential mismatches.
Common Pitfalls to Watch For
- Missing Manager App: If the
managerfolder doesn't exist inTOMCAT_HOME/webapps, you might have installed Tomcat without the Manager application. Reinstall Tomcat with the full distribution or deploy the Manager WAR manually. - Firewall/Security Group Blocks: Ensure the Tomcat server's port (default 8080) is open to incoming traffic from Jenkins.
- Credential Typos: Even a single wrong character in the username or password will cause authentication failures—triple-check these values.
内容的提问来源于stack exchange,提问作者Srinivasa Tadipatri

