Automatic deployement with Jenkins/jetty - continuous-integration

I would like to setup a continuous integration environment whereby after committing the source code, it triggers a build process that checks out the code, runs tests, constructs a war file and deploys the same to jetty server such that the users/testers can access the application on the browser.
Is this possible ?
Am using maven and jetty (I am not willing to change this. I use jetty both for development and in production). For CI, I am exploring Jenkins but am open to other opensource solutions.
If possible, how do I setup the environment.

I found a maven plugin named cargo. It has everything that I needed. I added it into my pom so that I could deploy and undeploy using mvn cargo:deploy/mvn cargo:undeploy. I created a new jenkins job and added undeploy, package deploy maven goals as build steps. Everything is working perfectly.

it's definitely possible. In a previous project, the build server (teamcity) copied the war to a shared nfs location between the build server and the application server and run a little shell script that connected to the application server and restarted jetty.
We used ant inside maven to manage the deployment, I remember we used the copy and sshexec tasks.
I'm sure that there are many other solutions, but that one worked for us.

I reviewed a lot of posts like this but I want something that is maven independent. Look here, this is selfcontained runner in on hudson/jenkins. You only need 'war', even manual jetty installation is not needed. Deploy war on jetty in Jenkins or Hudson job

Related

How to Deploy an artifact programmatically using Maven

I have a mission to develop an integration tool which allows from a source code folder to generate a WAR or OSGI Bundle and then deploys it in Tomcat or Karaf. I used Maven Embedder to create the artifacts, now my problem is how to configure my pom.xml to automatically deploy these artifacts.
on the internet I can't find any examples and also I'm new to the world of JEE and Maven.
please help me.
Find out how you can deploy artifacts to Tomcat or Karaf (without Maven).
Find out how you can deploy artifacts to Tomcat or Karaf programmatically.
Find a Maven plugin to use that deployment method.
The simplest solution would be to use something like the maven-resources-plugin to copy your built artifacts to the servers deployment directory but I am pretty sure that there are more sophisticated methods like http://tomcat.apache.org/maven-plugin-2.2/tomcat7-maven-plugin/deploy-only-mojo.html for deploying out of maven without plain file system mechanisms.
On a wider scale when working on problems like yours it always helps to take a step back and think about the abstract use case ("How to deploy something somewhere" followed by "How to deploy something somewhere programmatically") before going into detail and think about Tomcat or other application servers - and in most cases you will find out that there were hundreds of other who already had the same problem and solved it some way or the other.

Deploying to Nexus using Jenkins

We currently have Jenkins jobs to build the infrastructure for our suite of products. This job invokes ant to package various jar files under our build directory.
i.e.
build
lib
common.jar
ldap.jar
filesplit.jar
rmiservice.jar
.
.
.
My question is what is the best way to implement this so that we can deploy the built jar files to Nexus in bulk? Or is the best/only way to do this is to have a pom.xml file with each artifact specified with a build.gradle or Jenkins pipeline?
Thoughts? Best approach? Any help would be appreciated :) Thanks
Their is apparently an official plugin to deploy to nexus from an ant task.
https://github.com/sonatype/nexus-ant-tasks/tree/master/nexus-staging-ant-tasks
Once your deployment works from command line, automate it with Jenkins. Don't try to multi task you would loose time.
If you consider that deploying to nexus could be an excuse to migrate to a modern build system and replace Ant, go for Gradle
Agree w/ #jf-meier; migrate to maven. It has many benefits, though it can be a heavy lift.
Nevertheless, aether-ant works well and acts as a good transition phase as well. Documented to work with Nexus.
We've used it extensively to help teams for years. It uses the same engine that is within maven itself.

Maven deploy configs in pom.xml VS jenkins post-build action

Actually I see two alternatives how can I deploy my project to NEXUS:
Configure distributionManagement and deploy-plugin in pom.xml. That in jenkins I should only call mvn deploy and my project will be deployed to the environment
Create in Jenkins Post-build Actions -> Deploy artifacts to maven repository, where I can set repository URL, repository ID and so on
Question
What is pros and cons of each approach comparing with one another?
If you are configuring the deployment in Jenkins build configuration you are doing two things
you are separating the deployment from the project itself and therefore potentially can have different deployments for the same project
you remove the deployment setup from your version control setup/your source code
If you are leaving it in the pom using the default Maven setup you can run deployment of the project without modification from the commandline on any machine that has the credentials set up correctly. This can greatly help wit troubleshooting and it makes the setup independent of whatever CI server you use.
Both approaches as well as more custom setups like using the Artifactory Build Integration or the Nexus Staging Maven Plugin usage are fine. It will mostly depend on what you are aiming to achieve.
Personally I believe that the configuration should not be isolated to Jenkins and should remain with the project in the pom. But that is just my 2c.
Thanks for adding the Artifactory tag, now I can give you one more option - Artifactory Build Integration. With Artifactory Jenkins plugin you can configure your deployment options (target repository, whether or not you want to deploy build information, environment variables and custom properties etc.) without polluting your developers pom with ci-eyes only information.

Configure tomcat runtime using maven

Is it possible to configure a complete tomcat runtime within Eclipse using Maven/m2eclispe.
A maven goal to downloaded tomcat, create the server withing the eclipse environment and add the specified war files to the server ?
Or can some of these goals be implemented ?
You might want to take a look at this solution or check out the maven cargo plugin.
The first solution uses the sysdeo tomcat plugin, which I've personally used in the past, which worked quite well. It does not download tomcat though for you. You will have to do that manually.
Right now I'm working with the maven cargo plugin (not an eclipse plugin though), which will download a tomcat instance for your for development purposes.

Maven cargo plugin - redeploy specific deployable in standalone container?

I'm currently working on a project that consists of several services written in Java that are accessed by a Ruby/Rails front-end. In an attempt to simplify local development, I've created a separate project that adds all of our service WAR projects as dependencies, and uses the cargo-maven-plugin to deploy each of these as a deployable inside of a single embedded Jetty instance.
The issue I'm having is that I'd like to be able to tell cargo to re-deploy a single WAR out of the several that are being run at a time. Starting the entire set of services from scratch takes a bit, and is really unnecessary when only one deployable has actually changed. As far as I can tell, the cargo:redeploy goal only works for non-standalone containers, and I also haven't been able to find any documentation that its possible to specify what you want to re-deploy on the command line.
Is there a way to tell cargo to re-deploy a single deployable from the command line? I'm thinking of something along the lines of mvn cargo:redeploy -DgroupId=com.foo.bar -DartifactId=baz
Apologies if this isn't clear, or if there is a different approach that I should be taking entirely - I'm relatively new to Java development and Maven.
Thanks for any help.
Download the latest war file to your local machine, then redeploy using the following pattern:
mvn install:install-file -DgroupId=com.foo.bar -DartifactId=baz -Dversion=1.x -Dpackaging=war -Dfile=C:/cargo.jar

Resources