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

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

Related

How can I Trigger local maven project from remote Jenkins?

I have created a simple Selenium+java maven project locally on my machine. I am able to execute the testing locally triggering it with Maven.
I want to trigger it from Jenkins (which is installed on a remote machine (my company's QA server))
I am using the option 'custom workspace' of Jenkins.
As the Jenkins is on the server, it's not able to understand/locate the local path
'C:\Automation\MavenProject\'
How I can achieve this?
You can do it with master-slave concepts in Jenkins. Slave machine would be your windows machine which will connect to master Jenkins with the help of some jars. You need to create a node on your Jenkins server and after adding the configuration, you need to download the corresponding slave jars on your machine. Once you execute those jars on your local machine, it will interact with Jenkins server. Your Jenkins job can then perform further activities on your slave machine.
Also in the Jenkins job, you need to refer to this node by enabling the following option.
Restrict where this project can be run
1)Create a Maven Project in Jenkins, you may have to install some plugin if its not visible
Pushing your code to some type of version Control like Github
You need to configure Jenkins to provide GitHub build information and POM Location
Since you Jenkins is hosted up in the server, you have be able to access it public, you need to download Github integration plugin and configure jenkins to provide GitHub hook trigger for GITScm polling and similar action in github itself
This should get you going, also google or youtube, lots of solution , one example
https://www.youtube.com/watch?v=PhxZamqYJws

The correct way to deploy artifact from nexus

I am trying to build and CI environment and I think that it works because I can publish a jar into Nexus automatically.
Git
BitBucket
Jenkins
Nexus OSS
I am looking information about the deployment of maven projects automatically when it publish to nexus , but I am not sure about my initial idea.
My initial idea is to download the latest artifact from Nexus3 and use mvn spring-boot:run but I am not sure about my decission.
I read information about Puppet but I am not sure about this option, could anyone help to me about this process ? Or send to me another link in the StackOVerflow about this problem.
Regards !
Build a pipeline in Jenkins:
First job builds an artifacts and uploads it to the storage (in your case it's Nexus). It has to determine which version it uploaded - the easiest way to do that is to set the version by the job itself and then upload the known version (see a sample script at the bottom).
Then pass the known version to the downstream jobs (like deploying to envs). You'd need to tell Jenkins which version you just deployed - it's possible to write it into a key-value file and then use something like EnvInject plugin to read it as an env var.
To download an artifact from Nexus use wget/curl:
http://nexus.domain/nexus/service/local/artifact/maven/redirect?r={repository}&g={groupId}&a={artifactId}&v={version}&p={type}
Jenkins has several plugins for building pipelines, but you can start with a simple built-in possibility of jobs to invoke other jobs.
Couple of notes:
Do not use Maven for deployment. Maven is a build tool, it's not suitable for deployments. Write bash scripts and possibly use Docker for deployment automation.
Do not use LATEST/SNAPSHOT/RELEASE versions - you need to have a deterministic deployment (if it's repeated with the same params it deploys the same artifact).
A sample script that sets a snapshot-like version (so it's possible to upload the artifact to snapshot Maven repo):
VERSION=`mvn help:evaluate -Dexpression=project.version | grep -v "^\["| grep -v Download`
VERSION=${VERSION/%-SNAPSHOT/} #get rid of -SNAPSHOT if it's there
VERSION="$VERSION-"`date +"%Y%m%d.%H%M%S"`"-$BUILD_NUMBER"
mvn versions:set -DnewVersion=$VERSION

Is direct-to-heroku-client compatible with latest heroku API jar?

I've already configured my project to use direct-to-heroku-client.jar (https://github.com/heroku/direct-to-heroku-client-java) with heroku-api-0.24.jar and
when I test deploy of WAR artifact - it says "Failed to deploy 'war-test-artifact': com.herokuapp.directto.client.DeploymentException: Deploy not accepted".
I investigated that within direct-to-heroku-client API artifact might be uploaded to https://direct-to.herokuapp.com:443/direct during deploying, but it does not happened. So, I just want to know, if
https://direct-to.herokuapp.com:443/direct will be support soon somehow or not and is the direct-to-heroku-client relevant to heroku API v3?
That project is deprecated, and not supported (I updated the docs to reflect this).
Instead, you should be using either:
Heroku Maven plugin
Heroku Deploy CLI
For more information, see the Heroku Dev Center article on WAR Deployment.

How to deploy Ratpack API into remote server?

I have created an API using Ratpack and Groovy. All the GET, POST apps are working locally. Now I want this to move it to some remote server(say dev environment). How can I do this?
To start and run the app in local, I have to do either "gradle run" or "Run the Ratpack.groovy as a groovy script" from eclipse IDE. Then it says "Ratpack Server running in localhost:8080". And then I can use the APIs as localhost:8080/api/.../.../... but at the same time when I try to run it as JAVA Application, I am getting error as:
{"#timestamp":"2016-06-02T14:47:06.026+05:30","#version":1,"message":"Starting server...","logger_name":"ratpack.server.RatpackServer","thread_name":"main","level":"INFO","level_value":20000,"tags":null}
Exception in thread "main" java.io.UncheckedIOException: java.io.IOException: Is a directory
at ratpack.util.Exceptions.uncheck(Exceptions.java:52)
at ratpack.groovy.Groovy.ratpack(Groovy.java:112)
at ratpack.groovy.Groovy$ratpack.callStatic(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:206)
at Ratpack.run(Ratpack.groovy:22)
To deploy it in prod, I moved the jar to the server. After that what should I do to start the Ratpack server or rather API service?
I would recommend setting up a CI pipeline that builds a java jar and deploys the artifact to your target environment.
I recommend using the Shadow Plugin from John Engleman https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow
This plugin produces a shadow jar (similar to Maven's shaded jar) that can optionally include bash scripts or batch scripts for starting your application.
High level suggestion:
Add the shadow plugin to your gradle build file
plugins {
id 'io.ratpack.ratpack-groovy' version '1.3.3'
id 'com.github.johnrengelman.shadow' version '1.2.3'
}
Have your CI server or you manually execute `gradlew installShadowApp
SCP/FTP this artifact from your build/installShadow directory to your target server
Invoke the shell script from build/installShadow/$appName/bin/$appName to start application
For a more maintainable solution I would recommend registering this shell script as a service or with a solution like monit/upstart/ etc
For a more detailed example on deploying to Heroku as an example take a look at my notes: http://danhyun.github.io/2016-gr8confeu-rapid-ratpack-groovy/#deploying_to_heroku

Maven/Jenkins automatic download/copy

I'm in a team to develop plugins in java.
We got Maven, a repository and Jenkins,
And I got myself a debian-server to test my applications.
When I push my commits, this happens:
Push in repository, upload and build in Jenkins.
Users download these .jar files and upload these to their server
What I want to be happen:
There are two ways,
First: After building with Jenkins: Download these files,
Second: When pressing "maven build", maven builds my applications and copy these to my server
How can I do this?
(Sorry for my bad English: I'm German)
If I understand you correctly, following scenario should help.
create two jobs
first job builds your artifact and archives it: user will be able to download it, job is triggered by source modification
second job is only executed manually (and requires two plugins, listed below), copies artifacts from first job and then uploads them to the server
Following plugins you would need to install:
copy artifact plugin to enable jenkins to copy artifacts from another job
publish over ssh plugin to enable jenkins to upload binaries and run commands on remote servers
You want when you push your SCM repository, to get Jenkins build into your local projet (update your jars), then manipulate send your final build to your server. Is that you want ?
If yes, I think that plugin would be interesting :
http://evgeny-goldin.com/wiki/Jenkins-maven-plugin#Supported_Plugins
you can manage jenkins goals from your pom.xml but I am not sure if you can get jenkins build.

Categories