Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

maven

jenkins

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

like image 835
Chris Beach Avatar asked May 09 '12 12:05

Chris Beach


People also ask

Why maven project is not showing in Jenkins?

Kindly note that If this Maven Project option is not visible, we need to check whether the "Maven Integration" plugin is installed in Jenkins. If not installed, then install it and restart Jenkins.

What is Mvn release prepare?

Preparing a release goes through the following release phases by default: Check that there are no uncommitted changes in the sources. Check that there are no SNAPSHOT dependencies. Change the version in the POMs from x-SNAPSHOT to a new version (you will be prompted for the versions to use)

How does Jenkins integrate with maven?

In the Jenkins dashboard (Home screen), click Manage Jenkins from the left-hand side menu. Then, click on 'Configure System' from the right hand side. In the Configure system screen, scroll down till you see the Maven section and then click on the 'Add Maven' button.

How does Jenkins release maven?

Few examples of different project types are Freestyle, Maven, Multi-configuration, Pipeline etc. Select the "Maven Project" amongst those options, configure your project based on your requirement. And then you'll be able to see the perform maven release option to the extreme right of your jenkins dashboard.


1 Answers

<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>
like image 63
Chris Beach Avatar answered Oct 01 '22 20:10

Chris Beach