How to run ant build through jenkins at scheduled times? - java

I have created some test cases and placed them in testng.xml file. I have created a build.xml(ant build) file which is running without any errors. now my task is that i need to run all my test cases through jenkins integration tool using ant build.
I have installed jenkins on my ubuntu system.
what are the further configurations like creating a job, scheduling tasks ???

The next step is to create a job. Then set the workspace of that job ( usually your project directory), set the scheduler to run whenever you want. For the syntax of the scheduler (chronos) you have a help button.
For example:
#midnight will run every midnight
* H/2 * * * will run every 2 hours.
After that set the build command and save. You're done! Try a manual build by pressing on "build now" to see if you have configuration mistakes, if you have correct them and done.

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 to set `killSoftly` for a specific Jenkins job?

My Jenkins build hangs between build and post-build steps.
The console output shows there is a 6-minute wait (but I've seen waits of up to one hour):
10:53:26 BUILD FAILED in 1m 7s
10:53:26 4 actionable tasks: 4 executed
10:53:26 Build step 'Invoke Gradle script' changed build result to FAILURE
10:53:26 Build step 'Invoke Gradle script' marked build as failure
11:09:29 [CucumberReport] Using Cucumber Reports version 4.9.0
I found this and this questions that have similar issues, and they say the solution is setting -DSoftKillWaitSeconds=0 in jenkins.xml.
However, I need a way to set the option for particular jobs only, without messing with global Jenkins settings (I wouldn't want to mess with other projects).
EDIT:
When I manually abort the job, before the [CucumberReport] step, Cucumber reports are still generated.
I also checked Abort the build if it's stuck checkbox in Build Environment options, with Time-out strategy set to No Activity (Timeout seconds = 2).
When I build the project with these settings, the build will fail with "Aborted after 0 seconds" shown in Build History, as before, but the console output will be the same. (Nothing changes, Cucumber Reports will be generated but after a certain timeout).
It is not possible to select a job-specific value for SoftKillWaitSeconds (the value is derived from the Jenkins core at a point where the job name is not known).
My recommendation is to fix the abort handling in your job itself, so it will not depend on a "soft kill timeout". If you're running on a Unix-ish system, you can ensure this by running your job in a new process group (set -m in bash) and (for example) setting up a proper exit trap.
We are using the Build-timeout plugin to kill stuck jobs with timeout strategy set to No Activity or Absolute. For me, this is a good approach when you are using freestyle projects.
The reason why your build is "Aborted after 0 seconds" is that most likely there are unfinished child processes.
From documentation:
Because Java only allows threads to be interrupted at a set of fixed
locations, depending on how a build hangs, the abort operation might
not take effect. For example,
if Jenkins is waiting for child processes to complete, it can abort
right away.
if Jenkins is stuck in an infinite loop, it can never be
aborted.
if Jenkins is doing a network or file I/O within the Java VM
(such as lengthy file copy or SVN update), it cannot be aborted.
You could try the absolute timeout strategy. You can define a global variable, so that you do not repeat the timeout value in jobs:
Go to "Manage Jenkins" > "Configure System".
Check "Environment variables" in "Global properties".
Add an environment variable name="GLOBAL_TIMEOUT_MINUTES" value="20".
Go to a configuration page of a project.
Check "Abort the build if it's stuck" in "Build Environment".
Select "Absolute" for "Time-out strategy". Of course, also applicable to other strategies.
Set "${GLOBAL_TIMEOUT_MINUTES}" for "Timeout".
Set timeout action "Abort the build".
If this is not working, you could try to look in the logs https://your-jenkins-server/log or in a thread dump.
The hanging may be caused by new/old version of a plugin. Try to find what are the unfinished child processes. Try to disable post-build actions one by one to find the one that may be the cause of the issue.
You can see https://superuser.com/questions/1401879/debugging-what-happens-when-a-jenkins-build-unexpectedly-pauses-or-hangs

multiple job plugin running job multiple time - Jenkins

I'm using multijob plugin, Where I have created a Job using it and configured 2 Job in it as shown here:
I've configured to run both job sequentially. But while I do build Its execution order is
Job 1
Job 2
Then Again
Job 2
Job 1
I want it to be configure, the execution should be only one time Job 1 and Job 2. How do I configure here ?
Steps to trigger multiple job using Multi Job Plug In:
In your first job that is "Rcontact_Dashboard_testSuite" click on Add build step
Then select trigger/call builds o other project
on Projects to build field just type "Rcontact_Main_TestSuite" that is your second job.
Then build the first job
This will run your first job after that it will trigger your second job.
Hop this will solve your issue. let me know your feedback.
Below configuration working for me.
I have used Multijob Plugin and configured my both job in different phases as shown Here

Execute batch application in background using Jenkins

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?

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