I have a Maven build job in Jenkins and in the "Build" section, I have given Maven Version and Root POM and in the "Goals and Options" filed, I am executing the pom with customized goals. I need to write the output of the execution to a file, I tried below
clean install -Dmaven.test.skip=true -nsu -l output.log
clean install -Dmaven.test.skip=true -nsu -DoutputFile=output.log
clean install -Dmaven.test.skip=true -nsu -Doutput=output.log
Nothing works for me. Could anyone please help in either the above way or any other option available to direct the output log to a file?
According to mvn -help, the following works for me:
clean install -l output.log
The file is stored to the job workspace, if you want to publish it as an artifact, you need to add a Publish artifact or Publish document post-step (or Publish document post-build option in Maven project).
Related
I have corporate Jenkins where I don't have access to Manage Jenkins option. I want to make a build of my java app using maven.
When I try to run mvn clean install:
dir("test/test2/project") {
sh "mvn clean install -Dmaven.test.skip=true"
}
I get the following error:
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/var/jenkins/workspace/test/test2/project). Please verify you invoked Maven from the correct directory.
I was trying to add mvn -f /var/jenkins/workspace/test/test2/project/pom.xml (I have pom file in the folder) but it did not work.
I also tried
withEnv(["PATH+MAVEN=${tool 'maven-3.5.0'}/bin:${env.JAVA_HOME}/bin"]) {
sh "mvn --batch-mode -V -U -e clean install -Dmaven.test.skip=true"
which also did not work.
I would like to point to maven and java which are installed on the agent but can't seem to sucseed.
Any idea?
Can you try something like below?
dir("test/test2/project") {
sh "mvn clean install"
}
Working with a multi-module project. Want to run maven commands as follows:
mvn clean compile
Then maven install phase without again executing maven compile
Not possible.
You would need to call the goals directly, phases cannot be run separately.
you can (now) skip phases by directly calling the goal via
mvn <plugin>:<goal>
e.g.
mvn compiler:compile
see this answer for details.
for install it should be mvn install:install
In Opendaylight, Whenever a change I made, I will build the whole project instead of specific project. mvn clean install -DskipTests=true.. Is there any way to skip the whole build and build the particular pom.xml of project.. E.g In ovsdb, If I want to run southbound project alone what i have to do?
There can be a better way but the workaround I use is :
I use a bash script to copy the jars + config files.
If I make code changes to a module,
I build the modified module
Execute the script. to copy the built jar file, config files to the specific folder location inside System folder of the unziped ODL distribution.
I restart ODL. bin/karaf clean.
Part of the bash script which I use to update common jars+config
local.sh:
elif [ $1 == common ]; then
cp /home/user/workspaces/workspace-odl/myproject/common/implementation/target/common-impl-2.0.0-SNAPSHOT.jar /home/user/controller/myproject-karaf-2.0.0-SNAPSHOT/system/com/myproject/common-impl/2.0.0-SNAPSHOT/common-impl-2.0.0-SNAPSHOT.jar
cp /home/user/workspaces/workspace-odl/myproject/common/model/target/common-model-2.0.0-SNAPSHOT.jar /home/user/controller/myproject-karaf-2.0.0-SNAPSHOT/system/com/myproject/common-model/2.0.0-SNAPSHOT/common-model-2.0.0-SNAPSHOT.jar
cp /home/user/workspaces/workspace-odl/myproject/common/config/src/main/resources/initial/89-common.xml /home/user/controller/myproject-karaf-2.0.0-SNAPSHOT/system/com/myproject/common-config/2.0.0-SNAPSHOT/common-config-2.0.0-SNAPSHOT-config.xml
rm /home/user/controller/myproject-karaf-2.0.0-SNAPSHOT/etc/opendaylight/karaf/89-common.xml
echo "Updated common"
Execution:
./local.sh common
This will copy the updated jars, and the next time you will run ODL, updated jars will be picked up.
This is fast, and doesn't require me to rebuild whole ODL project.
If you are using for first time build the whole project using command
mvn clean install -DskipTests -Dcheckstyle.skip=true
For subsequent changes say you have changed in southbound-impl build southbound-impl using above command.
Next build southbound-karaf using above command. Then you can start the karaf to test. for target/assembly/bin/karaf.[sh|bat]
Assuming you have the appropriate entries in you Maven settings.xml, you can build any module in an OpenDaylight Maven project by running Maven in its folder; for ovsdb southbound:
cd southbound
mvn clean install
Alternatively, from the project's root:
mvn -f southbound clean install
If you only want to build a single module (none of its children):
mvn -pl southbound clean install
(These are all standard Maven options.)
OpenDaylight includes a few nice extras you can use to iterate on builds more quickly:
the q profile skips all goals which don't contribute to the resulting artifact (static analysis, tests, documentation...):
mvn -f southbound clean install -Pq
updated JARs can be installed directly in a pre-existing Karaf system folder using the addInstallRepositoryPath variable:
mvn -f southbound clean install -DaddInstallRepositoryPath=.../karaf/system
(replacing ... with the appropriate path).
These can be combined, so
mvn -f southbound clean install -DaddInstallRepositoryPath=.../karaf/system -Pq
builds and installs the JARs in an existing Karaf (which can even be running — it will re-load the bundles).
I have a Maven project that generates a zip file with maven-assembly-plugin on mvn package
MyProy
|--pom
|--src/...
|--target
|---MyProy-something-1.0.0-SNAPSHOT-zip (contains /1.0.0-SNAPSHOT/...)
I created a Jenkins job and configured a shell script execution as a post step. This script copies the zip to a folder (/something) and unzips it
|-/something
|---1.0.0-SNAPSHOT
|---...
This works fine for builds. However I want to do the same when I launch a release. I installed Jenkins release plugin and in "configure release build" I added this tasks:
Before release build -> Maven task mvn release:prepare
After successful release build -> Maven task mvn release:perform
After successful release build -> Execute shell script - Copy zip and unzip.
I see the mvn release:perform execute correctly, for instance with version 1.0.0 but the problem is that when the script (3.) is launched it applies to the next development version (1.0.1-SNAPSHOT) instead of the release version (1.0.0).
This is how I managed to work around the problem:
Before release build
mvn release:prepare
After successful release build
mvn release:perform
mvc scm:checkout -DscmVersion=${releaseVersion} -DscmVersionType=tag
-f ${WORKSPACE}/target/checkout clean install
Execute shell script with copy and unzip
To sum up, after the release:perform I checkout the brand new tag, execute a clean install in the location of the downloaded tag and finally I execute the script that copies the zip and unzipes it.
I've added some gradle task to my project. However, I still want to continuous build to run maven. My first attempt was to add an explicit script
script:
- mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
- mvn test -B
This doesn't work. I tried to rename the build.gradle file. This doesn't work either. I probably need to remove gradlew but before that, is there a better solution?