I am using Jenkins to set-up a DevOps pipeline for a Java project. And am stuck at one scenario of deployment. If somehow there has to be roll-back of build on Tomcat server and build that has to replace this one has to be last stable build.
Suppose build#20 is deployed on server which is stable and build#21 is deployed in next build cycle but after deployment its found that this new build has issues. Now i want to replace this build by the previous build that is build#20.
The plugin I am using on Jenkins doesn't provide the facility of roll-back. Please help me out.
Plugin for deployment : https://wiki.jenkins-ci.org/display/JENKINS/Deploy+Plugin
Just re-build build#20, call it build#22, and deploy it.
"Deploy" your build results to a deploy-candidate location and only (really) deploy them to Tomcat from there after it has turned out that your complete build process is stable.
Related
I am currently thinking about the potential solutions for building and running a Jenkins Maven project. I am a Jenkins Noob and what I currently think of is providing a Maven Plugin that runs the project right after the build and test phase. This feels wrong... .
So my basic question is, is it possible in Jenkins to configure a process to build a maven project and execute it right away and taking care for not interfering with it by starting another process and rebuilding it since a change arrived.
If this is possible it would ease the task by omitting the "Let's write a Maven plugin".
What do you means by 'execute'? Your program is a jar? If you do have to deploy it, there is tools in Jenkins to deploy with the build phase. If not, I think you can always make a 'Post build' command like java -jar nameofprogram.jar
In Jenkins you can configure jobs to execute multiple Maven targets when the jobs are run. I don't know if this answers your question, but you should be able to accomplish what you want by using "post build steps" and trigger certain behaviour from there.
What I want to achieve is as:
Build the maven project and push the jar to repo, using maven & jenkins.
Deploy the application, using script.
Run jmeter test cases and display test results in jenkins dashboard.
First jenkins build my project and push it to repo.
Then I have defined a post build step in jenkins to run script on remote server, this script deploys and starts my application.
Then I have created a post build action in jenkins to invoke top-level maven targets, to run mvn verify, which triggers the jmeter-maven plugin, which runs the test cases on my already running application.
Is this a good approach and if not please let me know a better way to do this?
Thanks in advance.
The bit that may be missing here is how Jenkins knows if the build should be marked as passed or failed? Even if jmeter-maven-analysis plugin execution did exit with zero exit code, it doesn't mean performance-wise the application is fine. It may be, but don't have to be. I came across that kind of concerns some time ago and provided a solution. Check project wiki for usage example and more information.
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.
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:
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.
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.
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
I have Java projects built with maven, with artifacts (.jar .war) deployed to Nexus release repository. Also Jenkins is used for CI (building every hour) and automatically deploys to Tomcat (integration testing environment). We are using maven-release-plugin for artifact deployment to Nexus, that is done on local PC.
I need to automate deploying to other 3 environments: Test, Prerelease, Production.
There are 2 problems:
It is unlikely that I can use Jenkins for that, as Jenkins can't know when current version is promoted as good & released.
The location of .jar .war is different after every release
http://nexusserver:8081/nexus/content/repositories/releases/com/company/projectname/component/0.2.4/
A bit similar questions is
Deploying from Nexus to Tomcat (via Jenkins/Hudson)
It sounds like you need what is often referred to as a "build pipeline" or "build pipeline manager" a term which I believe became popular with the (excellent) book "Continuous Delivery".
There is an open source Jenkins plugin called Build Pipeline Plugin that may meet your needs.
https://wiki.jenkins-ci.org/display/JENKINS/Build+Pipeline+Plugin
We are currently working on a distributed Java EE-Application and have therefore a separated test and production system.
Compiling and Bundling is done via an Ant-Task. Now we want to deploy the Jar-Files of the different servers to the test-servers and run the JUnit Integration / Function-Tests there. If they succeed, then the current version should be deployed to the live-servers.
Plain Unit-Tests are executed by Hudson.
Is that possible with Maven and is there any information or best practice available?
Yes. Hudson has maven integration. Take a loot this wiki and this link.
You can set unit test case thresholds for your job to see if it does not pass a certain number of test cases. In that the deploy plugin will not get invoked and the app will not get deployed.
Take a JAR built from Ant and reuse it. I would add a Maven repository to your environment such as Artifactory, Archiva, or Nexus and deploy to that using Ivy. You almost certainly need to use a Maven repository to be happy with Maven for anything other than small scale personal projects. http://ant.apache.org/ivy/
Use Maven to grab the JAR from the Maven Repository. For this, just use a normal Maven dependency declaration.
Run Maven on the QA server, with the JUnit tests declared in that project. If that succeeds, deploy the JAR to the production server. For this, the details depend on the production server. If it's a WAR, I would use Cargo, but if it's a JAR it really depends on what's executing the JAR - you might need some sort of file copy, scp, etc. http://cargo.codehaus.org/
Hudson and TeamCity both have deployment features as well. You just set up a job to run (in this case the Maven job) and tell the CI server to deploy on success.