Execute batch application in background using Jenkins - java

I have a Spring Batch application with a Task Scheduler based on this implementation.
Basically, during development in Eclipse, I execute the following maven goal:
mvn clean install exec:java
to execute the batch application. The above command executes my MainApp class which has a static main class that loads the Application context file and from there, Spring takes control. During development, this is not a problem since I need to see the logs in the console. But during integration in my Jenkins server I am encountering a problem with this setup.
In Jenkins, when I try to build the application using the above goal, the build never finishes because it holds on to the console. I need the build to finish so that the downstream projects are also built. My question is, how do I tell Jenkins to ignore the console and proceed to the next build process? In short I want to start the batch application on the background without it holding on to the console so that my build can continue.
What I have tried so far:
I tried changing the goals such that exec:java will be called as a Post Step. Still it does not work. What are other methods in which to perform this?

Related

First Run of Maven Built Application in IntelliJ fails

I have a project that I want to build with Maven but run with IntelliJ, i.e. not delegate run actions to Maven. I have an Application Run Configuration that points at the main class of my project, with a Before Launch action of 1. Run Maven Goal 'Project Name: compiler:compile'. The FIRST time only that I run this config, I get:
Error: Could not find or load main class xx.Main
Caused by: java.lang.ClassNotFoundException: xx.Main
And on subsequent (using the exact same run config) runs, it works perfectly.
Note: if I have a separate Maven Build Target for my project and I run that first and then the Application Run Target (without the build before launch), it works first try. I've also tried setting a Before Launch action to run that Build Target, with the same failure as a result. This ONLY occurs when I try to build and run in the same target.
It seems like IntelliJ is caching the build state BEFORE anything runs and then using that same state AFTER the Maven Build has run... Does anyone know why this occurs and if there is a way to fix it, or am I just stuck running it twice after every clean? Happy to provide more detail if required.
Background as to why I want to do it one step: I'm setting this up for some very junior (and VERY prone to messing things up) devs and the fewer steps there are, the better. I don't want them to have to think about how to make it run.
As suggested by tgdavies in a comment, it's possible to make this work first time by adding an IntelliJ Build task following the Maven Build task in the Before launch steps. My Main Run Target now has Before launch: 1. Run Maven Goal 'Project Name: compiler:compile' 2. Build. Obviously this solution is less than ideal but at this stage, I'll take functional. I'll be raising a ticket with IntelliJ and hopefully it will be addressed... Thanks tgdavies!

How can maven-cargo2-plugin recognize that my Spring Boot application already has an embedded Tomcat running?

I have an application that I built with Spring MVC (so it's a web front end), Spring Data and so on. It runs on an embedded Tomcat and I can reach the index by:
java -jar MyApplication.jar
Going to "https://localhost:8443" in a browser or curl
(I have a couple of runtime configurations in Eclipse that make this faster and easier as well.)
Right now, everything is in maven, and everything builds (including with standard unit tests) by using:
mvn clean install javadoc:javadoc
(This gives me a jar file, a sources jar, etc.)
To do my front-end and integration testing, I need to have the application running. Basically, I need a fork or multiple threads (I guess that's right terminology?) where the first one will run my application or something, then the second one will run the tests.
Right now I'm trying to fiddle with maven-cargo2-plugin, but it's horking because it is having issues with the fact that my application has an embedded tomcat already running. Which makes sense--if cargo is starting a tomcat, it doesn't want to find one already running.
I'm pretty sure I'm not the only one doing this, but I'm at a loss. I've tried going through spring-boot-test to load the application context, and that isn't enough for my front end tests (HTMLUnit/Selenium).
I've gotten failsafe set up and this all runs in:
mvn verify
But I'm confused on how to configure the container for Cargo. Is this an "embedded" type? An "installed" type? "remote" (even though it's on the same machine)?
Like I said, this is the final lap. We have an executable jar already. I just need it to start up and then run until the verify step is over.
Any ideas?
I encourage you to use the spring-boot:run plugin which is already shipped with spring-boot
Usage: mvn clean spring-boot:run

Program to trigger "Build Now" on jenkins and display console output

I have an application that takes the changes and pushes on git. Now i want to create a deploy button on my application, clicking on which, will automatically trigger "Build Now" on Jenkins and display the console output on my application. (I am already storing the userid and password for jenkins within my application.) This will enable me to do everything within my application, from creating the changes, pushing to git and finally deploying it on jenkins and seeing the console output without actually going to jenkins and doing it manually.
More info:My application is built in Spring boot and thymeleaf as frontend.
Thanks in advance.
You can use Jenkins CLI
The command line interface can be accessed over SSH or with the Jenkins CLI client, a .jar file distributed with Jenkins.
with build command
One of the most common and useful CLI commands is build, which allows the user to trigger any job or Pipeline for which they have permission.
Jenkins also has a REST api that you can use, use POsT to trigger and GET for the reults
https://wiki.jenkins.io/plugins/servlet/mobile?contentId=753720#content/view/753720

automatically run external application, which use Cucumber for testing main application

We have application which use Cucumber framework for testing our second application, the applications runs on own processes (black box testing), currently we do following steps:
1) Run DB
2) Run main application
3) Run test application which use Cukumber framework for testing main application
Question is: how we can do this automatically by using TeamCity ?
Create a Command Line build step:
Point to the working directory
Run your Cucumber tests from the command line. Example.
Here is more info on Cucumber's CLI.
My approach would be to write a script that sets up all dependencies. I.e. starting the database, starting the second application and then run the Cucumber stuff. The script would be possible to run on the CI server, i.e. TeamCity or on a developers system so it is easy verify that they didn't break anything before committing.
Restricting the execution to TeamCity only would not be my preferred approach.
This lead toa solution taht depends on your dev and CI environment. Are you running on Windows or on Linux? The scripts will different depending on the operating system.

How to open and run a specific script from the command line in eclipse

I am trying to run an automated suite every day at the same time, so I want to create a task to open eclipse and execute the main script every day. Is there a way to do this from the command line?
Instead of using eclipse for it, use a software that is dedicated for it - continous integration servers are created for it. Check such titles like: hudson, cruiseControl, TeamCity
You are on the wrong path. Instead of trying to automate opening eclipse, executing a main... break the IDE dependency, write a portable build script using Ant or Maven and execute that build script outside the IDE (using a simple cron job or something more elaborated like a Continuous Integration tool but I'm not sure you need a CI tool for now, start with the build script).
So I am assuming that you want to automate something that you run from inside eclipse. if it's a build then I'm with the other guys that using a build script and CI is the way to go.
But in case it's not that use case...
Now, if you are using the "Run.." dialogs to do this you can actually get the command line paths, binaries and arguments that eclipse used to execute.
What you do is open up the debug perspective. Then run your script however you normally do.
Your Process should appear in the "Debug View" at this point.
Either while the process is running or after termination, right click on the process and open up the properties. (you may need to click 1 level down in the tree to get this option)
Under process info, inside of that there is a section "Command Line". This is the exact command line that eclipse executed behind the scenes to run.
you should be able to put this into a script (.bat for windows / sh for *nix) and schedule accordingly.
edit: added in assumptions, changed to use process info terms which is what is on the properties screen.

Categories

Resources