Jenkins to Run Maven Build on Linux or Windows

Jenkins to run Maven build on Linux or Windows

Pipeline scripts can contain groovy code, so branching with if is allowed. You can test your environment with System.properties['os.name'] and depending on the result, use sh or bat:

node {
def os = System.properties['os.name'].toLowerCase()
echo "OS: ${os}"
if (os.contains("linux")) {
sh "mvn install"
} else {
bat "mvn install"
}
}

Jenkins maven build fail in linux machine

Seems like your shell script has failed since it can't find maven on this node. Check if you can see the maven installation directory defined on Manage Jenkins -> System Information as M2_HOME environment variable. You can also check at your terminal using env command.

Also %PLATFORM_CORE_VERSION% is used to dereference the environment variable under windows, use $PLATFORM_CORE_VERSION under Unix machines (as long as it configured)

Java+Maven builds on Jenkins but not on local machine

I a compile action works on Windows but not on OSX/Linux the most common failure is a file with wrong uppercase or lowercase character in the file name (or directory name).

As Windows works case insensitive it is able to find and access the file.

OSX and Linux are working case sensitive and therefore are not able to acces the file.

Check the directory names of the package some.package.in.projectA
and the filename of the Java files that they exactly match the package respectively class name(s).



Related Topics



Leave a reply



Submit