6

I use the Maven task in Azure DevOps Pipelines. I need to activate a concrete profile, but I don't understand how to do it. I try to pass a profile in 'options' and in 'goals' but it doesn't work. How can I activate a profile correctly?

- task: Maven@3
  displayName: maven_project_profile
  inputs:
    mavenPomFile: 'my_project/pom.xml'
    options: '-DskipTests=true -P someprofile'
    goals: 'clean deploy -p someprofile'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    testRunTitle: 'fixBypassService'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.8'
    mavenVersionOption: 'Default'
    mavenAuthenticateFeed: false
    effectivePomSkip: false
    sonarQubeRunAnalysis: false

I can see in logs:

2020-01-13T08:45:13.1695224Z [command]/usr/share/apache-maven-3.6.2/bin/mvn -f /home/vsts/work/1/s/my_project/pom.xml -DskipTests=true -P someprofile clean deploy -P someprofile

But the profile 'someprofile' isn't activated in reality.

typik89
  • 907
  • 1
  • 10
  • 23

3 Answers3

7

I was wrong. A profile is activated correctly if you pass it e.g. in goals:

- task: Maven@3
  displayName: maven_project_profile
  inputs:
    mavenPomFile: 'my_project/pom.xml'
    goals: 'clean deploy -P someprofile'

I couldn't see a result of activating because there were issues of accessing some resources inside an agent but this is no matter for the current post. Everything works correctly.

EDIT: the flag is capital P

Purfakt
  • 101
  • 1
  • 16
typik89
  • 907
  • 1
  • 10
  • 23
1

This is a working example of Maven@3 task:

      - task: Maven@3
        inputs:            
          mavenPomFile: 'pom.xml'
          mavenOptions: '-Xmx3072m'
          javaHomeOption: 'JDKVersion'
          jdkVersionOption: '1.11'
          jdkArchitectureOption: 'x64'
          publishJUnitResults: true
          mavenAuthenticateFeed: true
          goals: 'clean package -Pprod'

The -P (capital p) in the goals input let you pass the profile parameter.

And pay attention to the jdkVersionOption, jdkArchitectureOption and mavenOptions inputs, they can be very important in your build.

freedev
  • 25,946
  • 8
  • 108
  • 125
0

Azure DevOps maven task profile

I'm not very familiar with maven, so I'm not sure about the correct command to activate the profile.

But, for using the Maven task to activate a profile is like activating a profile with the command line in the goals.

So, to resolve this issue, you should make sure you could use the command line to activate the profile, then use the same command line in the goals.

You could check the document Introduction to Build Profiles for some more details:

mvn groupId:artifactId:goal -P profile-1

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • 1
    The resulting maven command in logs is correct. You can run and check it. Of course, I'm not going to duplicate a profile in one command. It's only to show you that I tried different ways. If I do the same via a script task, everything works correctly. But I would like to have the opportunity to do it via standard maven task – typik89 Jan 14 '20 at 09:38
  • @typik89, May I know your script task, would you mind share it to us? So that I could check it. – Leo Liu Jan 14 '20 at 09:41
  • 1
    Sorry, I was wrong. It works! Maven task activates a profile correctly – typik89 Jan 14 '20 at 09:59