Jenkins部署war包到tomcat7,报错

1、部署tomcat7,报错,信息如下:

[JENKINS] Archiving /opt/.jenkins/jobs/qxpt_jx-deploy/workspace/pom.xml to com.ichangyan.tsp/qxpt_jx/2.0/qxpt_jx-2.0.pom

[JENKINS] Archiving /opt/.jenkins/jobs/qxpt_jx-deploy/workspace/target/qxpt_jx.war to com.ichangyan.tsp/qxpt_jx/2.0/qxpt_jx-2.0.war
channel stopped
Deploying /opt/.jenkins/jobs/qxpt_jx-deploy/workspace/target/qxpt_jx.war to container Tomcat 7.x Remote
ERROR: Build step failed with exception
org.codehaus.cargo.container.ContainerException: Failed to redeploy [/opt/.jenkins/jobs/qxpt_jx-deploy/workspace/target/qxpt_jx.war]
	at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:189)
	at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:73)
	at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:116)
	at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:103)
	at hudson.FilePath.act(FilePath.java:990)
	at hudson.FilePath.act(FilePath.java:968)
	at hudson.plugins.deploy.CargoContainerAdapter.redeploy(CargoContainerAdapter.java:103)
	at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:61)
	at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:782)
	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:723)
	at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.post2(MavenModuleSetBuild.java:1037)
	at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:668)
	at hudson.model.Run.execute(Run.java:1763)
	at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:529)
	at hudson.model.ResourceController.execute(ResourceController.java:98)
	at hudson.model.Executor.run(Executor.java:410)
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:555)
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.list(TomcatManager.java:686)
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.getStatus(TomcatManager.java:699)
	at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:174)
	... 16 more
Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: http://172.16.xx.xx:8080//manager/text/list
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1626)
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:544)
	... 19 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:555)
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.list(TomcatManager.java:686)
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.getStatus(TomcatManager.java:699)
	at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:174)
	at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:73)
	at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:116)
	at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:103)
	at hudson.FilePath.act(FilePath.java:990)
	at hudson.FilePath.act(FilePath.java:968)
	at hudson.plugins.deploy.CargoContainerAdapter.redeploy(CargoContainerAdapter.java:103)
	at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:61)
	at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:782)
	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:723)
	at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.post2(MavenModuleSetBuild.java:1037)
	at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:668)
	at hudson.model.Run.execute(Run.java:1763)
	at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:529)
	at hudson.model.ResourceController.execute(ResourceController.java:98)
	at hudson.model.Executor.run(Executor.java:410)
Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: http://172.16.XX.XX:8080//manager/text/list
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1626)
	at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:544)
	... 19 more
Build step 'Deploy war/ear to a container' marked build as failure
Finished: FAILURE

分析:

这个问题是因为对于tomcat 7的user的权限定义引起的,如下

manager-gui — Access to the HTML interface. 

manager-status — Access to the "Server Status" page only. 

manager-script — Access to the tools-friendly plain text interface that is described in this document, and to the "Server Status" page. 

manager-jmx — Access to JMX proxy interface and to the "Server Status" page.

必须把部署用户的权限定义为“manager-script”,才可以成功部署。

解决办法:

1、需要修改一下tomcat的conf文件夹下的tomcat-users.xml文件

 

<role rolename="manager-gui"/> 

<role rolename="manager-script"/>

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

2、重启服务即可(linux下)

    ./shutdown.sh

    ./startup.sh

 

   好了,本次到此,如果觉得有帮助,需要更多测试相关技术,欢迎来交流,联系方式如下:

 

 

posted @ 2016-01-27 09:27  黑夜小怪  阅读(11180)  评论(0编辑  收藏  举报