Jenkins下部署war包到tomcat服务器发生错误

1.当jenkins中部署war到tomcat,控制台输出错误信息

Started by user itcast
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/web_demo_freestyle
The recommended git tool is: NONE
using credential 5011e58f-4eef-4a0b-abf3-141adc28972b
 > git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/web_demo_freestyle/.git # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url git@192.168.118.181:itheima/web_demo.git # timeout=10
Fetching upstream changes from git@192.168.118.181:itheima/web_demo.git
 > git --version # timeout=10
 > git --version # 'git version 1.8.3.1'
using GIT_SSH to set credentials gitlab-ssh-auth
Verifying host key using known hosts file
 > git fetch --tags --progress git@192.168.118.181:itheima/web_demo.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision e7cedcadca227f1e448e91f010d7f25bf47a0a8b (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f e7cedcadca227f1e448e91f010d7f25bf47a0a8b # timeout=10
Commit message: "加入代码审查的脚本"
 > git rev-list --no-walk e7cedcadca227f1e448e91f010d7f25bf47a0a8b # timeout=10
[web_demo_freestyle] $ /bin/sh -xe /tmp/jenkins17666718797868895672.sh
+ echo 开始编译构建
开始编译构建
+ mvn clean package
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------< com.itheima:web_demo >------------------------
[INFO] Building web_demo 1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ war ]---------------------------------
[INFO] 
[INFO] --- clean:3.2.0:clean (default-clean) @ web_demo ---
[INFO] Deleting /var/lib/jenkins/workspace/web_demo_freestyle/target
[INFO] 
[INFO] --- resources:3.3.1:resources (default-resources) @ web_demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/web_demo_freestyle/src/main/resources
[INFO] 
[INFO] --- compiler:3.11.0:compile (default-compile) @ web_demo ---
[INFO] Changes detected - recompiling the module! :source
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file with javac [debug target 1.8] to target/classes
[WARNING] bootstrap class path not set in conjunction with -source 8
[INFO] 
[INFO] --- resources:3.3.1:testResources (default-testResources) @ web_demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/web_demo_freestyle/src/test/resources
[INFO] 
[INFO] --- compiler:3.11.0:testCompile (default-testCompile) @ web_demo ---
[INFO] No sources to compile
[INFO] 
[INFO] --- surefire:3.2.2:test (default-test) @ web_demo ---
[INFO] No tests to run.
[INFO] 
[INFO] --- war:3.4.0:war (default-war) @ web_demo ---
[INFO] Packaging webapp
[INFO] Assembling webapp [web_demo] in [/var/lib/jenkins/workspace/web_demo_freestyle/target/web_demo-1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/var/lib/jenkins/workspace/web_demo_freestyle/src/main/webapp]
[INFO] Building war: /var/lib/jenkins/workspace/web_demo_freestyle/target/web_demo-1.0-SNAPSHOT.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.102 s
[INFO] Finished at: 2024-04-08T19:38:26+08:00
[INFO] ------------------------------------------------------------------------
+ echo 编译构建结束
编译构建结束
[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 9.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:1236)
	at hudson.FilePath.act(FilePath.java:1219)
	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:80)
	at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:47)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:818)
	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:767)
	at hudson.model.Build$BuildExecution.post2(Build.java:179)
	at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:711)
	at hudson.model.Run.execute(Run.java:1918)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
	at hudson.model.ResourceController.execute(ResourceController.java:101)
	at hudson.model.Executor.run(Executor.java:442)
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.118.183:8080/manager/text/list
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1997)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1589)
	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:1236)
	at hudson.FilePath.act(FilePath.java:1219)
	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:80)
	at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:47)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:818)
	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:767)
	at hudson.model.Build$BuildExecution.post2(Build.java:179)
	at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:711)
	at hudson.model.Run.execute(Run.java:1918)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
	at hudson.model.ResourceController.execute(ResourceController.java:101)
	at hudson.model.Executor.run(Executor.java:442)
Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: http://192.168.118.183:8080/manager/text/list
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1997)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1589)
	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

2. 原因是由于没有设置tomcat角色,以及访问限制删除

[root@tomcat conf]# vim /opt/tomcat/conf/tomcat-users.xml
#增加这一段配置到 user中
<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"/>

注释这一行,这个 Valve 的作用是只允许来自特定IP地址范围的请求访问Tomcat

[root@tomcat conf]# vim /opt/tomcat/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" />
  -->
#这个 Valve 的作用是只允许来自特定IP地址范围的请求访问Tomcat

3. 重启tomcat

[root@tomcat tomcat]# /opt/tomcat/bin/shutdown.sh
[root@tomcat tomcat]# /opt/tomcat/bin/startup.sh

4.在jenkins中进行配置tomcat凭证

5. 开始构建,构建成功输出

Started by user itcast
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/web_demo_freestyle
The recommended git tool is: NONE
using credential 5011e58f-4eef-4a0b-abf3-141adc28972b
 > git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/web_demo_freestyle/.git # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url git@192.168.118.181:itheima/web_demo.git # timeout=10
Fetching upstream changes from git@192.168.118.181:itheima/web_demo.git
 > git --version # timeout=10
 > git --version # 'git version 1.8.3.1'
using GIT_SSH to set credentials gitlab-ssh-auth
Verifying host key using known hosts file
 > git fetch --tags --progress git@192.168.118.181:itheima/web_demo.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision e7cedcadca227f1e448e91f010d7f25bf47a0a8b (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f e7cedcadca227f1e448e91f010d7f25bf47a0a8b # timeout=10
Commit message: "加入代码审查的脚本"
 > git rev-list --no-walk e7cedcadca227f1e448e91f010d7f25bf47a0a8b # timeout=10
[web_demo_freestyle] $ /bin/sh -xe /tmp/jenkins4518584223216612980.sh
+ echo 开始编译构建
开始编译构建
+ mvn clean package
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------< com.itheima:web_demo >------------------------
[INFO] Building web_demo 1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ war ]---------------------------------
[INFO] 
[INFO] --- clean:3.2.0:clean (default-clean) @ web_demo ---
[INFO] Deleting /var/lib/jenkins/workspace/web_demo_freestyle/target
[INFO] 
[INFO] --- resources:3.3.1:resources (default-resources) @ web_demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/web_demo_freestyle/src/main/resources
[INFO] 
[INFO] --- compiler:3.11.0:compile (default-compile) @ web_demo ---
[INFO] Changes detected - recompiling the module! :source
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file with javac [debug target 1.8] to target/classes
[WARNING] bootstrap class path not set in conjunction with -source 8
[INFO] 
[INFO] --- resources:3.3.1:testResources (default-testResources) @ web_demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/web_demo_freestyle/src/test/resources
[INFO] 
[INFO] --- compiler:3.11.0:testCompile (default-testCompile) @ web_demo ---
[INFO] No sources to compile
[INFO] 
[INFO] --- surefire:3.2.2:test (default-test) @ web_demo ---
[INFO] No tests to run.
[INFO] 
[INFO] --- war:3.4.0:war (default-war) @ web_demo ---
[INFO] Packaging webapp
[INFO] Assembling webapp [web_demo] in [/var/lib/jenkins/workspace/web_demo_freestyle/target/web_demo-1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/var/lib/jenkins/workspace/web_demo_freestyle/src/main/webapp]
[INFO] Building war: /var/lib/jenkins/workspace/web_demo_freestyle/target/web_demo-1.0-SNAPSHOT.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.940 s
[INFO] Finished at: 2024-04-08T19:40:03+08:00
[INFO] ------------------------------------------------------------------------
+ echo 编译构建结束
编译构建结束
[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 9.x Remote with context null
  [/var/lib/jenkins/workspace/web_demo_freestyle/target/web_demo-1.0-SNAPSHOT.war] is not deployed. Doing a fresh deployment.
  Deploying [/var/lib/jenkins/workspace/web_demo_freestyle/target/web_demo-1.0-SNAPSHOT.war]
Finished: SUCCESS

6.进行访问,成功

7.如果还是输出同样的错误,建议重启jenkins和tomcat服务器,并且复制粘贴tomcat对应的角色代码,多试几次

  • 8
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值