How do I quicky compile and run Jenkins from source? - java

How can I compile (if changes were made) and run Jenkins from source on localhost without running any tests?
Obviously that I read the documentation but this doesn't really say how to run it without any tests, only to how to compile the war file.
The funny part is that the doc page even specifies on how to run inside the debugger but that's not what I want.
I just want to write a script that compiles and runs it, ideally even killing it if it was already running (so I can run it multiple times without worrying about being unable to start).
I am on MacOS but I am pretty sure that solution would work on almost any system.

Jenkins used maven as it's build tool, so just add this system parameter
mvn -DskipTests=true ...
to skip the tests.

It seems that running Jenkins from build needs something long like like
mvn clean install -pl war -am -DskipTests && java -jar war/target/jenkins.war

Related

How to skip tests when debugging test with Intellij which installs the package before debugging

I have a maven project where I'd like to debug tests using IntelliJ. The problem is that when I select the test I'd like to debug IntelliJ first executes mvn install command in order to be able to execute tests against the most recent code, and after this executes the test and allow me to debug.
I have multiple problems with this:
the project contains hundreds of tests which takes 2-3 minutes to execute them. It is super slow especially when I need to restart debugging frequently
if my test compiles, but still fails I can't start debugging since it will fail the maven install part of the execution and IntelliJ doesn't kick off debugging
I haven't found any hints in IntelliJ's doc about how to manipulate the mvn install part of the debugging process
yes, I could start maven in debug mode in the command line and attach IntelliJ to it, but that process is very fragile and it is 2021... let me use the IntelliJ fully...
I tried to add a Before launch step like mvn clean install -Dmaven.test.skip=true, but it results that the test classes won't be compiled.
My question is how can I manipulate the whole Debugging process is IntelliJ, especially the maven install part? What is the good solution here?
I'm using TestNG and the user interface doesn't offer me any option to do manipulate mvn install part.

IntelliJ maven vs normal maven

I would like to add my own commands to delete a specific folder in the mvn repository whenever I run a maven command.
For using maven through the command prompt, this is quite easy since we just update apache-maven-3.5.3\bin\mvn.cmd .
However, I noticed that when we run mvn from intelliJ Maven projects Tool Window, the command run is the following:
C:\mbakOrg\Oracle\JDK\jdk1.8.0_60\bin\java -Dmaven.multiModuleProjectDirectory=
C:\mbakOrg\_CODE\MNE_ARCHIT_GIT\_REPOS\sg-template-store -Dmaven.home=C:\mbakOrg\build\apache-maven-3.5.3 -
Dclassworlds.conf=C:\mbakOrg\build\apache-maven-3.5.3\bin\m2.conf "-javaagent:C:\mbakOrg\devel\JetBrains\IntelliJ IDEA
2017.1.3\lib\idea_rt.jar=42633:C:\mbakOrg\devel\JetBrains\IntelliJ IDEA 2017.1.3\bin" -Dfile.encoding=UTF-8 -classpath
C:\mbakOrg\build\apache-maven-3.5.3\boot\plexus-classworlds-2.5.2.jar org.codehaus.classworlds.Launcher -Didea.version=2017.1.3 clean install
So how will I add a command that will run every time?
Since maven in InteliJis using a custom way to run maven.
Explanation
My problem is basically that the mvn -U command does not properly pull the newest code all the time. Additionally, we are all using a snapshot of a parent project that is being updated quite often to fix issues.
I would strongly discourage modification of mvn.cmd. Even if you figure out how to do it in command line, and in InteliJ, then think about moving to some kind of Continuous Integration framework, like Jenkins for example, which will use default mvn.cmd?
If there is no possibility to achieve what you want with existing Maven tools, I would recommend writing own Maven plugin, (see this tutorial), and put required functionality there. It will guarantee, that this particular piece of code will be executed in all the environments, and this is the way to make sure, that the command will be launched every time.

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.4.3:test

Hi I want to install one program from my university which should work.
https://github.com/graphium-project/graphium
I tried to install through command prompt but it didn't work (see pic 1.). I also tried in Eclipse and Update project (this advice I found on forum) but then it is same.
thank you for any help
As per the errors on the command prompt, it looks like test cases are failing. You can go to surefire-reports folder of the failing module and see what is actually failing.
If the only thing you want is to install the project, then you can simply skip running tests using mvn clean install -DskipTests
You can also run mvn clean install -e to see more logging of the error that caused the test to fail

Using maven in scripts or adding a script-runner task at the end

I'm using maven on both mac and linux to build a .war file for a website. I'd like to know the best way to automatically run a script that will deploy the website to the server after a build.
What I am currently doing is I have a deploy.sh script that will run
mvn -P<PROFILE> clean package
and will then do a bunch of ssh / scp stuff to copy the target/file.war to the web server and run a bunch of commands to start/stop tomcat - clean out the logs etc.
Problems
Although various stack posts say using $? is supposed to catch the error code from maven I have yet to get it working and if for some reason I have a bad maven build I have no way to detect it. I would not like to do all my deploy tasks if the build fails.
Options?
1) Is there a correct way to detect a bad "build" from maven and have my script abort (I guess i could check if the war doesn't exist ...??)
2) Is there a maven "plugin" that will actually handle this for me, and if so could somebody provide a small code example.
I would do two things in the shell script which calls Maven and the deployment commands:
test whether the WAR file exists before attempting to deploy it, as you suggest yourself;
save Maven output to a timestamped log file for reference.
You may want to consider using maven as the entry point to the deployment and let it call deploy.sh rather than the other way around. This way maven will fail the build if something goes wrong.
The Ant plugin should be able to help with this, take a look at the second example here. It allows you to run a script and fail on error if desired.

What is the process with Maven project to compile and test the code?

I have maven project imported in my eclipse. Now I need to start making changes to it and test it with the integration test (out of App server). Currently, the integration test is run out of server using openEJB container.
My basic question is, what is the regular process to compile, build and test with Maven?
mvn install
Maven -> Update Project.
Run my test from command line
Is it how it is done? I am specifically interested in knowing mvn install commands.
So should I do all three steps before I can test it?
Example: I just wanted to print something and see what is the output. For this I guess I need to do all these steps?
The openEJB container needs classes so it can load them.
There is a wonderful Maven quick-reference sheet at http://maven.apache.org/guides/MavenQuickReferenceCard.pdf
First, you should be aware that unit tests and integration tests are separate and are run from separate plugins and at separate parts of the maven lifecycles. Unit tests are run with surefire and integration tests are run with failsafe.
You want to run integration tests and the failsafe documentation says:
NOTE: when running integration tests, you should invoke maven with the (shorter to type too)
mvn verify
rather than trying to invoke the integration-test phase directly...
This is the best way to run integration tests directly in maven. It will run all the preceding steps necessary (eg: compile) in order to run the integration tests. It won't waste time doing an install because install happens immediately after verify.
But if you're running the tests locally, it may be a better idea to run your integration tests directly in your IDE. That will give you a much faster feedback loop.
If it is Eclipse project the most reasonable thing is to do everything not from command line but from Eclipse. Assuming you have m2e plugin installed, go to your_project->run as->Maven test and run it.
You dont need neither install nor package phase to run Maven tests, package will create a jar which is not needed for tests, install will copy this jar to local repo which is also useless. When Maven run tests it uses compiled classes from target dir and ignores project's jar if even it exists.
Yes, mvn isntall is the most popular option. It compiles, packages and tests your project.

Categories