How to setup CI for my application with Jenkins - java

I have a scheduled build in Jenkins which runs everyday at 12:00 AM. I want to set up a CI server for my project. I want to set it such a way that before every build, my application is undeployed and once the build is successful, it's deployed and up again, running on the server. This is possible if I manually add some server in my system and put the shell command in pre-build and post-build actions to undeploy and deploy manually but is it possible directly with Jenkins? As the name suggests, Jenkins - CI server, is there any way how can I do it with Jenkins?
Note: I have maven jetty plugin and have set a goal clean install jetty:run in my application but it doesn't suit my requirement in Jenkins for CI server.

Yes, Jenkins will run any script at any time, so you can do this very easily. You don't need to use pre- and post-build actions. Build steps work very well for this use. You can add multiple steps to a single Jenkins job/project.

Related

How can I create a Jenkins pipeline to run a Java Application on a schedule?

I'd like to create a Jenkins pipeline on an existing Jenkins environment that would run an application (hosted on an online SCM repository) on a schedule. The application to run would be a Java .jar file. Is my understanding correct that this would entail a Jenkins Job that would build an application on a server, then through a script (perhaps .sh?) of some sort run that application. Upon completion the build would be cleaned up and removed from the server. Is this correct? Am I missing any parts or steps in my understanding? How can I structure such a jenkins job?

Jenkins Build and Deploy

I am learning Jenkins. Can someone tell me if my understanding is correct?
To build the app:
I commit my code and push my branch to my remote repository.
Jenkins sees my commit and triggers off a build (possibly using maven install).
Jenkins runs all the tests and if all pass, a war/ear is created. This artefact is pushed to nexus.
To deploy to an environment:
A deploy script in my branch contains steps to deploy the app to, say, Tomcat.
Jenkins goes to Nexus, retrieves the latest artefact (built above), and deploys this app to Tomcat.
Other steps in the deploy file shutdown and restart Tomcat as necessary, possibly testing to make sure the app started and is ready to serve requests.
Am I right in saying that a deploy doesn't need to build the latest artefact, that it uses that last one pushed to Nexus, or is a fresh one built every deploy?
It's all according to how you set up your build on Jenkins and/or git.
Jenkins can be configured to monitor your repository (repo, for short) and to kick off a build when it detects a change.
Jenkins can be configured to run a build. You provide the Maven command-line arguments; Jenkins just orchestrates the commands you give it.
Some of the steps you provide Jenkins will be shell code. This is how you can run custom shell scripts, say to access Nexus. Things don't happen by themselves; if you tell Jenkins to deploy an artifact, say by using Maven, then Jenkins will invoke the deployment command as you told it to.
It is highly irregular for an app deployment to arrogate responsibility to start, restart, or shut down your server (Tomcat). That could be done via Jenkins, sure, but it's at a higher "pay grade" than an app deployment should have. Keep it simple; if your Jenkins build is managing an app for testing and deployment, keep its focus on the app and not on the server.
Jenkins is magical, but it's not a mind reader. It will do none of the things you said unless you tell it to. That said, the process you outlined is a reasonable one, whatever tool you use to enact it. Jenkins certainly can do those things, if you set it up accordingly.

Run Automation Scripts after Deployment on Tomcat Server using Jenkins

I've deployed a servlet based web application(War file) in Tomcat server using Jankins and Maven. Now I want to run some selenium automation scripts on same application, Can it be achieved by Jenkins.
Its like Deploy web application on Sever and once deployment is successful run automation scripts using jenkins..
Please Help..
Two possible ways :
1) Add post build step to your current task and run the scripts there.
2) Add another task ex. "app-automation-scripts" that runs every time that your current task is builded correctly.
Yep,
you can add maven plugin to jenkins, (installed by default most of times)
then declare your project as war in pom.xml
then add a post processing "maven" to your maven build config and configure it with options "war:war"
-- options you can add for a maven build is: clean install build and etc. war option is for creating war files.
Or:
simply run a bash command using your jenkins build configuration.
Former needs installation of maven plug-in and configuring it,
Later needs configuring your maven to be run on the jenkins server by user named "jenkins".

Continuous integration - git flow

I'm really nooby in 'Continuous integration'. And have a question about it.
Is it possible to create jar, ear or war file and deploy it on jboss every time I merge my develop branch (release) with master branch. I user gradle for build my project. I prefer something without user interface. My server runs on ubuntu server.
You should use a build server (like Jenkins) that could be configured to poll your git repository and run the build upon commit and on a successful build it would deploy (by a script or some plugin) the build product (jar/war) onto your JBoss server.

maven deploy goal failing

I am using eclipse with maven2 plugin.
When doing a Run-As -> build with a goal of 'deploy' I am getting this error:
Error message:org.codehaus.plexus.component.configurator.ComponentConfigurationException: Class 'org.apache.maven.artifact.repository.ArtifactRepository' cannot be instantiated
I'm not sure I even need to do a 'deploy', I have another build that does a 'compile' goal, and from what I have learned doing a Run-As -> Run on Server (tomcat) is enough to deploy my application locally to tomcat.
Do I need run this build 'deploy' goal to run locally, should I just delete it and use 'run on server'?
Running mvn deploy won't "deploy your application on Tomcat", deploy is something different here, deploy is a phase done in an integration or release environment and copies the final package to the remote repository for sharing with other developers and projects.
In other words, unless you are dealing with a remote repository to distribute your application (and this requires to configure a valid <distributionManagement/> section in your POM), just forget about deploy for now, this is not what you think it is :)
So, to run your application and "deploy it on Tomcat" from Eclipse, use Run As > Run on Server. If you want to run it from outside Eclipse, you can use mvn tomcat:run but this isn't really appropriate here (this goal is an handy way to run a webapp without importing it in a IDE). And if really you want to deploy your application on Tomcat from the command line, the Maven Tomcat plugin supports many methods for Deployment. But again, I don't think that this is what you're looking for for now.

Categories

Resources