Operations 3 min read

How to Configure Jenkins for Maven Builds Across Multiple Environments

This guide explains how to set up Jenkins to run Maven builds for different environments (dev, beta, prod), including commands to skip tests, deploy to Nexus, and specify profile parameters, with screenshots illustrating the correct configuration to avoid common errors.

Java Backend Technology
Java Backend Technology
Java Backend Technology
How to Configure Jenkins for Maven Builds Across Multiple Environments

In projects with multiple development, beta, and production environments, parameters such as resource, resource.beat, resource.dev, and resource.prod are used to differentiate settings.

Environment settings diagram
Environment settings diagram

Typical Maven commands for these scenarios are:

mvn clean install -Dmaven.test.skip=true
mvn deploy -Dmaven.test.skip=true
mvn clean install -Pdev -Dmaven.test.skip=true

When Jenkins runs without explicit parameters, it defaults to the resource profile and does not build for the specific dev, beta, or prod profiles.

To configure Jenkins (v2.46.1) to use the desired profile, set the “Goals and options” field with the Maven goals only (do not prepend mvn). The correct entry looks like:

clean install -Pdev -Dmaven.test.skip=true

Providing the full command with mvn in this field will cause an error, as shown in the screenshot below.

Jenkins configuration screenshot
Jenkins configuration screenshot
Error screenshot
Error screenshot

After setting the correct parameters, the project builds successfully.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Build Automationci/cdDevOpsmavenJenkinsEnvironment Profiles
Java Backend Technology
Written by

Java Backend Technology

Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.