I can't get Jenkins to deploy a war file on a Tomcat8 server. Why can't Jenkins deploy to Tomcat?
when I run the Jenkins job, I got this exception:
[DeployPublisher][INFO] Deploying /var/jenkins_home/workspace/Deploy_to_Tomcat_server/webapp/target/webapp.war to container Tomcat 8.x Remote with context null
ERROR: Build step failed with exception
java.net.ConnectException: Connection refused (Connection refused)
I think it has to be a problem with both docker containers, so I will describe what I have done.
Both Jenkins servers and Tomcat8 are running on my local machine in docker containers. So that both can see each other, I have created a common network.
~ % docker network ls
NETWORK ID NAME DRIVER SCOPE
da6fc157710c bridge bridge local
...
// network bridge already exists!
~ % docker network create --driver bridge my_jenkins_tomcat_network
378ef3f01e215207e90ca0a6e93e89a9610be1e9bd972f94f02f9b1ce6199923
**// Run jenkins container**
~ % docker run -d -p 8080:8080 --name jenkins_container_test --network my_jenkins_tomcat_network jenkinsci/blueocean
08a2ce5e609f0c50e3a4c9ce73a5c88918e6a0ab69c582d75bc44162ae7e58fd
**// Run tomcat container. I had an image name mywebapp with Tomcat8...**
~ % docker run -d -p 80:8080 --name tomcat_container_test --network my_jenkins_tomcat_network mywebapp
5ac868dbeb69512c7c2d5b62f067de72592a01e763cf5b20808d22c06de1fe0e
~ % docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5ac868dbeb69 mywebapp "catalina.sh run" 9 seconds ago Up 8 seconds 0.0.0.0:80->8080/tcp tomcat_container_test
08a2ce5e609f jenkinsci/blueocean "/sbin/tini -- /usr/…" About a minute ago Up About a minute 0.0.0.0:8080->8080/tcp, 50000/tcp jenkins_container_test
I can inspect both containers and the new network:
~ % docker network ls
NETWORK ID NAME DRIVER SCOPE
da6fc157710c bridge bridge local
378ef3f01e21 my_jenkins_tomcat_network bridge local
~ % docker inspect my_jenkins_tomcat_network
[
{
"Name": "my_jenkins_tomcat_network",
"Id": "378ef3f01e215207e90ca0a6e93e89a9610be1e9bd972f94f02f9b1ce6199923",
"Created": "2021-04-12T08:07:52.770548349Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.23.0.0/16",
"Gateway": "172.23.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"08a2ce5e609f0c50e3a4c9ce73a5c88918e6a0ab69c582d75bc44162ae7e58fd": {
"Name": "**jenkins_container_test**",
"EndpointID": "80adf0fe02288d76f24e675ad0fdf25bf89ac64ac135dee03cdd4b91a74a6d3e",
"MacAddress": "02:42:ac:17:00:02",
"IPv4Address": "**172.23.0.2/16**",
"IPv6Address": ""
},
"5ac868dbeb69512c7c2d5b62f067de72592a01e763cf5b20808d22c06de1fe0e": {
"Name": "**tomcat_container_test**",
"EndpointID": "ca216dc9302db6eee66393d9210aab4e4236c7442dba5c3701bcebc11b2e9463",
"MacAddress": "02:42:ac:17:00:03",
"IPv4Address": "**172.23.0.3/16**",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
]
I can exec bash in Jenkins container and ping tomcat container:
~ % docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5ac868dbeb69 mywebapp "catalina.sh run" About an hour ago Up About an hour 0.0.0.0:80->8080/tcp tomcat_container_test
08a2ce5e609f jenkinsci/blueocean "/sbin/tini -- /usr/…" About an hour ago Up About an hour 0.0.0.0:8080->8080/tcp, 50000/tcp jenkins_container_test
~ % docker exec -it -u:root 08a2ce5e609f bashh
OCI runtime exec failed: exec failed: container_linux.go:370: starting container process caused: exec: "bashh": executable file not found in $PATH: unknown
aironman@MacBook-Pro-de-Alonso ~ % docker exec -it -u:root 08a2ce5e609f bash
bash-5.0# ping 172.23.0.3
PING 172.23.0.3 (172.23.0.3): 56 data bytes
64 bytes from 172.23.0.3: seq=0 ttl=64 time=0.163 ms
64 bytes from 172.23.0.3: seq=1 ttl=64 time=0.139 ms
...
In my tomcat container, I have modified tomcat-users.xml file with this default content:
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="tomcat" password="tomcat" roles="manager-gui"/>
<user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status"/>
**<user username="deployer" password="deployer" roles="manager-script"/>**
When I create the Jenkins job, I use the credential deployer and tomcat url as shown above
I have tried too with internal ip, 172.23.0.3, no luck.
I have read this link, without responses, and it is bit different, so I think it is legitimate to answer the question.
One way to achieve this goal is to install this plugin , configure sshd in tomcat container and create a post task in Jenkins in order to copy the war file to webapps folder.