Building multiple Maven profiles for a single Jenkins job Building multiple Maven profiles for a single Jenkins job jenkins jenkins

Building multiple Maven profiles for a single Jenkins job


You could create a Jenkins matrix job. A matrix job allows the same job to run with changing settings (in your case: a string).

Each changing setting is called an axis. In your case you would create a string axis containing the two values: dev and prod.

That way your job would run twice, with both values.

However: your usage of profiles is dangerous. Since the profile used to run the build is not codified into your artifact, your break the "one source revision should always lead to exactly the same target artifact" contract of Maven (see: http://www.blackbuild.com/how-to-really-use-maven-profiles-without-endangering-your-karma/ for a more detailed explanation)

Consider creating either two different artifacts using classifier (-dev and -prod) or even better: create two separate modules of your build, each one creating only one of your target artifacts.


In Maven, if you use mvn -Pdev,prod, then you are activating both profiles simultaneously in one command.

It seems you want 2 distinct run of the command, i.e. something you would achieve on the command line by doing 2 builds:

mvn -Pdev install; mvn -Pprod install

In jenkins you can achieve this with either

  • one free style project job (with 2 shell builders running the mvn -P$PROFILE install tasks)
  • 2 maven type jobs (that you can chain one after the other using "build after other projects are built").


In addition to Matrix job and multiple maven invocations in a free-style job, there's another way: Run top-level Maven targets as a pre-build step and run the other command via maven jenkins plugin.

Make sure that the pre-build step uses the same maven repo as the other command by supplying -Dmaven.repo.local=/${whatever-it-is}/${EXECUTOR_NUMBER}.

Please refer to other answers for details on matrix job, etc.