How to config and run java project on Jenkins? - jenkins

I'm very new with Jenkins. I have tried to run projects on Jenkins but all are fail. I don't know whether the configuration is wrong or something. I have read the instruction on the jenkins-ci.org but I didn't understand anything. Anyone can give me a demo with Java project? By the way, show me the Jenkins configuration. Thanks all!

First question, do you want to build a Maven project?
If the answer is yes, you can create a new job with this template "Build a maven project".
You just have to configure your SCM tool (Git, SVN, ...) and when you want to pool your code (cron tab).
Next, in the build section, you have to declare your Maven goals (clean install for example) and the pom.xml file location (if the pom.xml file is not in the root folder).
That's all.

Related

Jenkins javadoc plugin doesn't generate documentation

I have installed Jenkins, create a project and configure it.
I run into a problem, Jenkins do everithing great except documentation generating.
Could anyone point me where I have done mistake, and how fix it?
Thank you.
------------------------ New information ----------
Console output:
I have renamed doc to javadoc directory, but it isn't help.
Here is screenshot of javadoc directory contents in console, it is clear that Jenkins plugin didn't generate documentation, but why?
It sounds like you are expecting the Jenkins plugin to produce the documentation. The Jenkins plugin merely copies files from the job's workspace folder to the build's archive area and provides a link to it. If your build steps don't produce Javadoc, then Jenkins won't be able to archive and provide a link to it.
Does your pom file include the maven-javadoc-plugin?
Are your build steps invoking a goal that includes Javadoc generation?
For example, "mvn jar" would compile Java and build the jar but not build the javadocs. Clearly you have executed a goal that executes the tests and provides a code coverage report, but that does not trigger the Javadoc goals either. You would need to make sure your build steps include a javadoc goal - i.e., mvn javadoc:javadoc. The standard goals can be found here: https://maven.apache.org/plugins/maven-javadoc-plugin/plugin-info.html .

change packaging value in pom during delivery to ibm RTC

I wanted to know if we have a plugin or can we write a pre delivery script that will change the value of packaging in my pom file. I want it updated from jar to pom. Can a plugin help with this? Suggestion welcome.
I tried-and-tested with maven profiles but do not want to go that route.
When you deliver in RTC, all you are doing is making your file available to any repo workspace monitoring the common Stream.
If you need to make some change to a pom.xml (without using profiles), then it is simpler to publish (that is add, commit and deliver) as well a script which would:
copy the pom.xml
change it as you need
use it with a mvn -f pom-modified.xml
The point is, as mentioned in this thread:
There is no out of the box solution for enforcing any pre-deliver steps.
You can try and add an RTC extension, as described in "RTC: Build On Deliver Participant" by Jorge Díaz.

How to debug the Jenkins plugin

I have built a new "Hello World" plugin for Jenkins and I was able to upload it onto Jenkins and it works successfully. I am now trying to make change to the plugin and debug it on Jenkins.
Note:
My Jenkins is deployed in my local tomcat, i build the hpi file and copy it to jenkins plugins folder, it works.
Now i want to ask how can i debug my plugin code? Suggestions with any IDE is welcome.
I also have questions about:
do i need to create a project for jenkins source in my IDE and develop my plugin base on it?
Currently i only create a project for the plugin, build a hpi file and put it to Jenkins.
I am not sure if this step is correct.
Thanks in advance!
I imagine you ran
mvn package
to create your package
To debug you can do
mvnDebug hpi:run
and this will copy all the dependencies down (rather than in your jenkins install) and run it in place
If you are using an IDE then this can be done from within it.
More help can be found in the plugin tutorial
Follow the tutorial to set MAVEN_OPTS, and using IntelliJ to add a Jetty Server to point the port to it.
execute from cmd:
mvn clean
set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n
mvn hpi:run
add a debug local Jetty Server from intelliJ and point it to port 8000 (port number is specified in above cmd)
In case of IntelliJ IDEA the easiest way is to use maven's Run/Debug configuration.
Just add hpi:run in "Command line" filed and start Debug as usual.
When the console says that your "Jenkins is fully up and running", open a browser and go to http://localhost:8080/jenkins/ and your code will stopped at break point (if any).

Jenkins, how can I archive a single subdirectory (without it's whole tree structure above)?

I'm using Jenkins to do nightly build of an iOS static framework. The output that I care about is in this directory:
ios/build/Release-iphoneuniversal/MySpecialProject.framework
I'd like to use the "Archive the artifacts" action to archive "MySpecialProject.framework", but when I do this, it creates a whole archive with the entire leading directory structure. The docs say to look at how Ant does this. I'm not familiar with Ant, so I'm at a loss here.
The main point of this is to make the "MySpecialProject.framework" available as as artifact to other projects being built with Jenkins. So, thinking that I could use the "Copy Artifact" plugin to do that. But I can't really get past this thing where it creates a full directory structure here. I just wan "MySpecialProject.framework" to be the top-level artifact.
Thanks in advance.
I fixed my own problem, by putting in an "Execute Shell" command:
mv ios/build/Release-iphoneuniversal/MySpecialProject.framework .
Then in the post-build action, "Archive the artifacts", I was able to just archive "MySpecialProject.framework/**"
This seems to work quite well. Since each time Jenkins runs the job, it creates a new workspace, I don't have to worry about issues with "mv". Works fine.

Intellij IDEA, build artifact using Ant?

I might be missing something, but I have been struggling with this problem for some time now.
I have an Web application with Ant build script. I would like to set up an Artifact to this module, (which is the .war file, generated using ant), so that I could deploy this war file, to the configured Tomcat server.
But I am not able to figure out, how to make Intellij use my Ant script to build artifact. I see an option to Run Ant Targets, but this just runs the Ant target and Intellij then proceeds to generate Artifact, in the usual way.
Please let me know if the question is ambiguous. The problem is not Ant Integration with Intellij. I could just use the Ant window and run any target and also could make an Ant target run as part of Build. The problem is to associate an Artifact to a module and leverage the Ant script to build that artifact. I need this to enable, tight tomcat integration, Since while integrating the Tomcat server, I can specify an artifact to be deployed.
Note: Intellij IDEA version 11.1
IDEA can either deploy Artifact or the External Source (directory or file) that is built by Ant or any other tool:
It's not possible to associate IDEA Artifact with Ant build.

Resources