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
Cron Error with Using Backquotes
How to Copy a File with '$' in Name in Linux
Bash (Or Other Shell): Wrap All Commands with Function/Script
Is It Good Practice to Use Mkdir as File-Based Locking on Linux
Cmake Set Environment Variable
Setting Up Jenkins Slave on MAC Os
Bash Script to Run a Constant Number of Jobs in the Background
How to Run Command During Docker Build Which Requires a Tty
Objdump and Resolving Linkage of Local Function Calls
How to Extract One Column from Multiple Files, and Paste Those Columns into One File
Bash Scripting - Iterating Through "Variable" Variable Names for a List of Associative Arrays
How to Find Out Where Is My Code Causing Glib-Gobject-Critical
How to Create a File with Any Given Size in Linux
What Does It Take to Be Durable on Linux
Shell Script for Process Monitoring
What Does Two Dots Before a Slash Mean? (../)
How to Get No. of Lines Count That Matches a String from All the Files in a Folder