Jenkins 自动部署到Tomcat 报The username you provided is not allowed to use the text-based Tomcat Manager

很多同学都遇到下面情况了吧:

The username you provided is not allowed to use the text-based Tomcat Manager (error 403)

Jenkins 自动部署到Tomcat 报The username you provided is not allowed to use the text-based Tomcat Manager

 

我也被坑了很久, 网上的解决方案大多只说了一步:

编辑 Tomcat 配置文件 tomcat8/conf/tomcat-users.xml, 添加如下内容

 <role rolename="manager-gui"/>
  <role rolename="admin-gui"/>
  <role rolename="manager-script"/>
  <user username="tomcat" password="tomcat" roles="manager-gui,admin-gui,manager-script"/>

配置了之后, 好多人还是部署不通, 此时先快速验证一下:

Jenkins 自动部署到Tomcat 报The username you provided is not allowed to use the text-based Tomcat Manager

如果返回403, 那说明少个文件, 再进行如下操作:

tomat_home/conf/Catalina/localhost/下 添加manager.xml

<Context privileged="true" antiResourceLocking="false"   
         docBase="${catalina.home}/webapps/manager">  
             <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />  
</Context> 

 

再部署, 发现一下舒服了, 部署成功!