jenkins打包部署到tomcat报错
[DeployPublisher][INFO] Attempting to deploy 1 war file(s)
[DeployPublisher][INFO] Deploying /var/lib/jenkins/workspace/web_demo_freestyle/target/web_demo-1.0-SNAPSHOT.war to container Tomcat 8.x Remote with context null
ERROR: Build step failed with exception
org.codehaus.cargo.container.ContainerException: Failed to redeploy [/var/lib/jenkins/workspace/web_demo_freestyle/target/web_demo-1.0-SNAPSHOT.war]
	at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:176)
	at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:81)
	at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:167)
	at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:136)
	at hudson.FilePath.act(FilePath.java:1172)
	at hudson.FilePath.act(FilePath.java:1155)
	at hudson.plugins.deploy.CargoContainerAdapter.redeployFile(CargoContainerAdapter.java:133)
	at hudson.plugins.deploy.PasswordProtectedAdapterCargo.redeployFile(PasswordProtectedAdapterCargo.java:95)
	at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:113)
	at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:123)
	at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:81)
	at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:48)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:809)
	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:758)
	at hudson.model.Build$BuildExecution.post2(Build.java:179)
	at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:702)
	at hudson.model.Run.execute(Run.java:1937)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:100)
	at hudson.model.Executor.run(Executor.java:433)
Caused by: org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The username you provided is not allowed to use the text-based Tomcat Manager (error 403)
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:710)
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.list(TomcatManager.java:882)
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.getStatus(TomcatManager.java:895)
	at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:161)
	... 19 more
Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: http://192.168.0.102:8080/manager/text/list
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1900)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:577)
	... 22 more
org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The username you provided is not allowed to use the text-based Tomcat Manager (error 403)
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:710)
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.list(TomcatManager.java:882)
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.getStatus(TomcatManager.java:895)
	at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:161)
	at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:81)
	at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:167)
	at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:136)
	at hudson.FilePath.act(FilePath.java:1172)
	at hudson.FilePath.act(FilePath.java:1155)
	at hudson.plugins.deploy.CargoContainerAdapter.redeployFile(CargoContainerAdapter.java:133)
	at hudson.plugins.deploy.PasswordProtectedAdapterCargo.redeployFile(PasswordProtectedAdapterCargo.java:95)
	at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:113)
	at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:123)
	at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:81)
	at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:48)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:809)
	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:758)
	at hudson.model.Build$BuildExecution.post2(Build.java:179)
	at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:702)
	at hudson.model.Run.execute(Run.java:1937)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:100)
	at hudson.model.Executor.run(Executor.java:433)
Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: http://192.168.0.102:8080/manager/text/list
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1900)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:577)
	... 22 more
Build step 'Deploy war/ear to a container' marked build as failure
Finished: FAILURE

jenkins打包部署到tomcat报错Build step ‘Deploy war/ear to a container‘ marked build as failure_tomcat

解决办法:

修改tomcat安装目录/conf/tomcat-users.xml,添加用户及权限

vi /usr/local/tomcat/apache-tomcat-8.5.55/conf/tomcat-users.xml
<tomcat-users> 
    <role rolename="tomcat"/>
    <role rolename="role1"/>
    <role rolename="manager-gui"/>
    <role rolename="admin-gui"/>
    <role rolename="manager-script"/>
    <user username="tomcat" password="tomcat" roles="manager-gui,tomcat,admin-gui,manager-script"/>
</tomcat-users>

jenkins打包部署到tomcat报错Build step ‘Deploy war/ear to a container‘ marked build as failure_linux_02

用户和密码都是:tomcat

注意:为了能够刚才配置的用户登录到Tomcat,还需要修改以下配置

vi /usr/local/tomcat/apache-tomcat-8.5.55/webapps/manager/META-INF/context.xml
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->

把上面这行注释掉即可!

jenkins打包部署到tomcat报错Build step ‘Deploy war/ear to a container‘ marked build as failure_tomcat_03

重启Tomcat,访问测试

/usr/local/tomcat/apache-tomcat-8.5.55/bin/shutdown.sh 停止

/usr/local/tomcat/apache-tomcat-8.5.55/bin/startup.sh 启动

访问: http://192.168.0.102:8080/manager/html ,输入tomcat和tomcat,

解决

jenkins打包部署到tomcat报错Build step ‘Deploy war/ear to a container‘ marked build as failure_linux_04