Chris Beach
Chris Beach

Reputation: 4392

Preventing Jenkins building (thus re-deploying) released versions of Maven projects

I'd like to prevent Jenkins building (thus re-deploying) released versions of Maven projects. Artifactory (rightly) doesn't allow released versions to be redeployed.

I'm using a Maven profile "jenkins" for all builds run in Jenkins

Upvotes: 7

Views: 725

Answers (1)

Chris Beach
Chris Beach

Reputation: 4392

<profile>
    <id>jenkins</id>
    <!-- This profile is activated by the "-P jenkins" switch when run on 
        the build server by Jenkins (continuous integration) -->
    <build>
        <plugins>
            <!-- Jenkins should only build -SNAPSHOTs -->
            <plugin>
                <artifactId>maven-enforcer-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <evaluateBeanshell>
                                <condition>"${project.version}".endsWith("-SNAPSHOT")</condition>
                                <message>Jenkins should only build -SNAPSHOT versions</message>
                                </evaluateBeanshell>
                            </rules>
                            <fail>true</fail>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

Upvotes: 5

Related Questions