Question

How can I automatically deploy a war from Nexus to Tomcat?

I have a maven web project which gets built and deployed (both SNAPSHOT and release versions) on Nexus successfully. I would like to know if there is feature/plugin in Nexus where it picks the released war and deploys on remote Tomcat automatically?

I know that you can deploy the war to remote Tomcat using maven-tomcat-plugin but would like to know if there is an alternative solution.

Please guide.

Was it helpful?

Solution

Typically you'd use a CI tool like Jenkins to run the Maven build that publishes your War file into Nexus. Nexus would then be used by whatever tool you're using to push the War onto the target tomcat environment:

enter image description here

There are lots and lots of options.

Jenkins post build SSH script

Run a post-build SSH task from Jenkins that does something like this on the target tomcat server:

curl "http://myrepo/nexus/service/local/artifact/maven/redirect?r=releases&g=myorg&a=myapp&v=1.1&e=war" \
     -o /usr/local/share/tomcat7/webapps/myapp.war
service tomcat7 restart

Rundeck

My preference is to use Rundeck for deployments, because it has a Nexus plugin, providing convenient drop-down menus of available releases.

There is also a Rundeck plugin for Jenkins that can be used to orchestrate a CI process with Jenkins performing the build, hand-over to Rundeck for deployment, followed by a Jenkins call-back to run the integration tests.

Chef

I also use chef which can be used to automatically deploy software in a pull fashion.

The artifact cookbook has direct support for Nexus, whereas the application_java cookbook uses a more generic "pull from a URL" approach that also works well.

.. ..

The list goes on, so I hope this helps.

OTHER TIPS

We used UrbanCode for the deployment automation, retrieves war from Artifactory/Nexus and deploy to the target server.

I used the Nexus Rest-API, these endpoints downloads the artifact to Jenkins workspace.

In order to deploy Snapshot & Release to Tomcat we can create a Jenkins parameterized job and pass the parameters to the REST endpoint, also to deploy to a server like Tomact "Deploy WAR/EAR" Jenkins plugin will help.

Jenkins Parameterized Job

We can parameterize the endpoint and use as part of "Build" step along with "Execute Shell script" option for the build.

wget --user=${UserName} --password=${Password} "http://192.168.49.131:8080/nexus/service/local/artifact/maven/redirect?r=releases&g=${GroupId}&a=${ArtifactId}&v=${Version}&e=${TypeOfArtifact}" --content-disposition

Actual endpoints to Nexus looks something like below.

wget --user=admin --password=admin123 "http://localhost:8080/nexus/service/local/artifact/maven/redirect?r=snapshots&g=org.codezarvis.artifactory&a=hushly&v=0.0.1-SNAPSHOT&e=jar" --content-disposition

wget --user=admin --password=admin123 "http://localhost:8080/nexus/service/local/artifact/maven/redirect?r=releases&g=org.codezarvis.artifactory&a=hushly&v=0.0.5&e=jar" --content-disposition

Thanks
-Sudarshan

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top