Increasing Maven Project Version Using Jenkins / Git

I use Jenkins to create Maven Java projects and deploy them to the Nexus repository. I also use Git, although I'm more used to Subversion, so my knowledge of Git is limited.

I would like Jenkins / Maven:

  • Merging objects into the integration branch
  • Build merged code, run unit tests
  • If they pass, increase the Maven version number
  • Incorporate merged code in a source integration branch
  • Deploy the artifact to the Nexus repository

I understand that Git merging can be achieved this way: http://twasink.net/2011/09/20/git-feature-branches-and-jenkins-or-how-i-learned-to-stop-worrying- about-broken-builds /

I also read a lot about maven-release-plugin .

I am not sure how to achieve the above results. If I rigidly set the SCM details in each POM project, will the maven-release-plugin act only in this repository, and not in the local Jenkins local computer?

If I use the solution that Jenkins passes the environment variable to Maven to indicate the version number, then I expect that there will be problems with the local version in my IDE.

+6
source share
1 answer

Well, this is pretty hard to do. But it is doable. Let me explain the idea step by step.

  • First we need to merge the two branches. This is fairly easy to do with the Jenkins Git plugin, as it has this feature built into : Merge before build is available in Advanced in your project configuration.

  • So, we got the code combined between these two branches, we can move on to creating a project - a business, as usual, a Maven project in the Jenkins style.

  • Now we need to increase the project version and modules, fix the combined branch and push the artifacts to the repository. And here we have two options:

    • Use the maven-release plugin to work. Yes, it is possible, since no one said you would need to put the URLs in your pom, as this can be provided in two different ways. The plugin will use one of them with the command line -DconnectionUrl= . And if none of them are provided, he will check the release.properties file to get it from there. The last reserve is to go to the variable pom.xml ang get ${project.scm.connection} . Thus, you can easily use the plugin to do all the dirty work without any problems and enter this property using various methods provided by Jenkins.
    • You can use a combination of maven-versions-plugin (specifically versions: set and versions: commit goals) with maven-scm-plugin to tag and commit changes.

    In both cases, you can use the Mail steps with Startup only if the assembly succeeds and the Maven target is invoked at the top level, as usual. For all the settings mentioned above or described by a specific plugin, it is possible to easily provide them in the text box. To upload your artifacts to the Nexus repository, I would enable the Jenkins function to deploy artifacts to the Maven repository, which is available in your project configuration. This will require that you provide the repository configuration in the POM definition or as a property.

Hope it covers all your questions. If you need me to be more specific in any response range, feel free to ask.

+8
source

Source: https://habr.com/ru/post/911308/


All Articles