2

I have a problem when running Azure DevOps Pipeline.

I'm now using Spring Boot Maven Project. I want to run Build Pipeline without building test(src/test) files,because the project will build failure with test files, and it can be built successfully without test files.

Is there any settings or configs? Many thanks.

You can view the image to see the details, thanks. Please checkout the image for the log

jasonroy7dct
  • 29
  • 2
  • 8

3 Answers3

5

The solution provided by @Bright Ran-MSFT is good but doesn't focus on the Azure Pipeline way of skipping the tests. It's because one may NOT want to skip the tests forever, instead just for a few temporary instances. Hence, hardcoding test skips in pom.xml may not be a good idea.

Azure Pipeline's Maven task provides a different way of passing the parameters.
-Dmaven.test.skip=true or -DskipTests=true can be passed through options argument of Maven task. Something like this -

steps:
- task: Maven@3
  inputs:
    mavenPomFile: './pom.xml'
    mavenOptions: '-Xmx3072m'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.8'
    jdkArchitectureOption: 'x64'
    publishJUnitResults: false
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    goals: 'package'
    options: 'package -Dmaven.test.skip'
Sid
  • 145
  • 1
  • 11
3

We have the options argument in Maven@3 tasks that we will help to add extra command-line options for maven.

Azure DevOps Maven Tasks - Link

steps:
  - task: Maven@3
    inputs:
      mavenPomFile: './pom.xml'
      mavenOptions: '-Xmx3072m'
      javaHomeOption: 'JDKVersion'
      jdkVersionOption: '1.8'
      jdkArchitectureOption: 'x64'
      publishJUnitResults: false
      testResultsFiles: '**/surefire-reports/TEST-*.xml'
      goals: 'package'
      options: '-DskipTests=true'
Himank Batra
  • 301
  • 5
  • 3
1

You can try the following ways:

  1. Set maven.test.skip=true
  • In Terminal
mvn package -Dmaven.test.skip=true
  • Or in pom.xml
<project>
    <properties>
        <maven.test.skip>true</maven.test.skip>
    </properties>
</project>
  1. Use this -DskipTests in surefire plugin.
  • In Terminal
mvn package -DskipTests
  • Or in pom.xml
<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M1</version>
        <configuration>
          <skipTests>true</skipTests>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

To view more details, you can reference to the articles below:

Bright Ran-MSFT
  • 5,190
  • 1
  • 5
  • 12