1

Currently our companies Jenkins deploy process isn't set up to read external property files for testing. I would still like to write and run tests locally and then have tests be skipped when pushed to github (where a jenkins process gets kicked of to build the app and push it into a container).

Is it possible to programmatically tell surefire pluggin to only run in a local environment but not to run in the Jenkins pipeline?

I know I can use the following config:

<configuration>
     <skipTests>true</skipTests>
</configuration>

but this means I need to remember to comment and uncomment each time I push, and I would rather not do that.

Thank you

2 Answers2

2

The answer of @NullPointerExeption is an option. You can also use maven profiles for that. e.g.

    <profiles>
        <profile>
            <id>jenkins</id>
            <activation>
                <property>
                    <name>jenkins</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>

When a developer run tests they will be executed as skipTests is false by default

From Jenkins use

mvn clean verify -Pjenkins

This will skip tests. In general it's good to have a jenkins profile and place all the staff that it's related to jenkins environment in this profile More on profiles here

Haim Raman
  • 11,508
  • 6
  • 44
  • 70
  • This seems like a possible good solution for me, however, as I mentioned below to @NullPointerException, I have no control over Jenkins, so I'll need to talk to that team and see if and how that command fits into the process. Thank you. – reactFullStackDeveloper Jun 26 '20 at 14:46
  • 1
    Thats a good reason to have a Jenkins profile and place all the staff that it's related to Jenkins environment in this profile. After you will set it it will give you some flexibility on controlling your build without changing staff in Jenkins – Haim Raman Jun 26 '20 at 15:14
1

You can specify the build in your jenkins file to skip the test during build stage. This will ensure your project is build skipping tests

stages {
    stage('Build') { 
        steps {
            sh 'mvn clean package  -DskipTests' 
        }
    }
}
NullPointerException
  • 3,732
  • 5
  • 28
  • 62
  • while I have no doubt that this is a legitimate possibilty for some it is not an option for me. In my org, developers are split from the pipeline processes which is controlled by a hosting/ devOps group So I have no ability to control the Jenkins build. Rather they build a process that is meant for 'the greater good' so to speak. But I appreciate the feedback – reactFullStackDeveloper Jun 26 '20 at 14:44
  • 1
    Correct , but the jenkins file should be in your project that tells jenkins how to build your project. This step should go in your projects jenkins file – NullPointerException Jun 26 '20 at 19:47