Reputation: 919
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
Upvotes: 2
Views: 5003
Reputation: 12023
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
Upvotes: 3
Reputation: 3804
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'
}
}
}
Upvotes: 1