57
votes

We're trying to deploy a war file with Jenkins, but nothing seems to happen.

The project is built successfully, and we're using Jenkins deploy plugin. It is configured with the following options:

auto deploy plugin

Post steps are set to "run regardless of build result".

I have checked that the credentials are correct, as I can acces the manager page in my browser.

Here is the last part that Jenkins (Maven) outputs:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:24.506s
[INFO] Finished at: Tue Feb 14 12:10:45 UTC 2012
[INFO] Final Memory: 22M/52M
[INFO] ------------------------------------------------------------------------
channel stopped
Finished: SUCCESS

I can also change WAR/EAR file to something that doesn't exist, and it will not give me errors, which is kind of strange. What am I doing wrong here?

7
You don' get any messages (exception or not) related to the plugin? - Łukasz Rżanek
Theoretically - no. It's using Cargo, so it should be pretty straightforward. Still usually I got something in my job log in case of problems... Usually something like: ERROR: Publisher hudson.plugins.deploy.DeployPublisher aborted due to exception - Łukasz Rżanek
OK. Thanks for your time and effort, though! - whirlwin
I was facing the same problem before. It was caused by the wrong path of war file. If you have folder like workspace/YourProjectname/target/warfile.war. The path should be target/warfile.war only. - syamimi
@syamimi thanks, it helped me. But I wanted to know what if tomcat has different hosts, i.e. hosting multiple sites, in which case how to tell tomcat which host to deploy to ? - coding_idiot

7 Answers

105
votes

I was having the same problem, and in my case the (relative) path to the WAR file was incorrect. Apparently if you don't have it exactly correct (it needs to be relative to the workspace root) then the deploy plugin will silently fail. In my case the path was:

target/whatever.war

Once that was fixed, I ran into a different problem in that the plugin expects to connect to the manager/text version of Tomcat Manager, rather than the manager/html version that I usually configure by default. You'll need a line in your tomcat-users.xml file like the following:

<user username="tomcat" password="pencil" roles="manager-script"/>

(This is in addition to the "manager-gui" role you probably already have set up.)

Once those changes were made, the build and deployment worked just fine.

8
votes

I use the Hudson Post Build Task plugin to execute a curl against the /manager/text API

The plugins mentioned can be selected and installed from the list of available plugins in the Jenkins configuration.

Once you have the plugin installed you just need to enable the "Post build task" and add the next line:

curl -T - -u user:pass 'http://<tomcat-host>/manager/text/deploy?update=true&path=/<yourpath>' < <path_to_war_file>

For example:

curl -T - -u manager:123456 'http://localhost:8080/manager/text/deploy?update=true&path=/slim' < /target/dist/slim.war

You can also use wget, but with the command above you log the output and see if there was a problem with the deploy.


Here's documentation related to the /manager/text service

1
votes

Hm have you used Cargo plugin? Well, I also had the same configuration as you, Jenkins, maven and tomcat. But when I needed to deploy, I was simply using that plugin. It's been a while actually, but in Jenkins you were able to enter command prompt lines right? Like mvn clean install? So, what you can do is simply configure your pom for Cargo plugin and then add that line to your Jenkins:

mvn cargo:deploy -Pintegration

By this way, I was able to clean install my builds daily, and deploy them to Tomcat. Afterwards I was doing my rest tests.

1
votes

For what it's worth, the latest version of the Deploy plugin for Jenkins seems to only need the base url. So, for me, it was http://blah.com:8080

Before that, I'd tried a host of other options, including host-manager/html, host-manager/text

0
votes

Assuming that Jenkins is finding your pom.xml to compile. Set your Goals and options in your Jenkins configuration to compile package. Then Jenkins will attempt to find your war file and deploy it. Good Luck.

0
votes

I tried to use the solution of target/whatever.war but it's not work so i tried to use */.war and it's work

you can see that on jenkins the definitive guide EN You need to specify where to find the files you want in the other build job’s workspace, and where Jenkins should put them in your current project’s workspace. This can be a flexible regular expression (such as */.war, for any WAR file produced by the build job), or it can be much more precise (such as gameoflife-web/target/gameoflife.war).

or on Deploy to Tomcat with pluging DEPLOY

0
votes

keep the roles manager-gui,admin-gui for the user who was configured Jenkins page

example:-

 <tomcat-users>

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

 </tomcat-users>