Jenkins Maven Integration Plugin building all existing branches - maven

We are using Jenkins with multi-branch pipelines and the Maven Integration plugin. I configured the multi-branch pipeline to "Build whenever a SNAPSHOT dependency is built". When our dev branch was built, it seemed to build every branch of all dependent repos. How may we limit it to only build branch X when branch X is built?

Related

Configure Maven project as Jenkins Multibranch Pipeline

How can I configure a Jenkins Multibranch Pipeline as Maven project?
For a Maven project in Jenkins I get the option.:
Build Triggers
Build whenever a SNAPSHOT dependency is built
But for a Jenkins Multibranch Pipeline I don't get that option.
How to get that option for a Jenkins Multibranch Pipeline?
dEE.
I think it is not possible. But I can share workaround with you.
Create maven project job, configure webhooks between jenkins and gitlab. In Source Code Management add as much branches as you want.
You can create a multibranch pipeline in Jenkin by choosing "Multibranch pipeline " in the option
There is no poll SCM but you can use Scan Multibranch Pipeline Triggers instead. Also take advantage of WebHook if the SCM you use gives that option
and about Build whenever a SNAPSHOT dependency is built this option - I dont think there is a way to do this with multibranch pipeline because this option comes with maven-plugins and can only available in Maven Project. But with out this you can achive the same scenario in different way by following good practice.
Build the dependent project seperately and keep the generate artifact in Nexus or Artifactory, so that the other job will pull independently.
Always make a good practice to use RELEASE version not SNAPSHOT version

Finish Build trigger does not fire for feature branch

I have a TeamCity project configured with 2 build configurations 'A' and 'B'. The 'A' configuration is meant to run against a feature branch and build the solution. It also publishes packages to the team city nuget feed.
I am also using the Octopus Deploy teamcity plugin to automate the creation of releases and deployments in our Octo server. Any packages published by a build configuration to the TeamCity nuget feed are not available to any build steps within the same build configuration so a second build configuration must be created to consume the packages.
As a result the 'B' build configuration is the Octo deployment step and it has a snapshot dependency to build A and an artifact dependency to build A. The artifact dependency has 'Get artifacts from' set to 'Build from the same chain'.
The build chain runs without issues when run with the teamcity vcs default branch. However the 'B' build config does not trigger when the 'A' build config runs against a feature branch. When looking at the build chain in teamcity when a build occurs on a feature branch the 'B' build config says 'Not Triggered'.
I can't find any clear solution to this problem and whether or not this is actually supported by TeamCity. It sounds like in earlier versions of TeamCity (~v7) this was not supported but that the introduction of snapshot/artifact dependencies solved the issue.

Jenkins maven-release-plugin

In Jenkins (latest), Maven 3.0.x, I have a project (Java source code).
I'm using M2 release plugin, which provides a nice "Perform Maven Release" button on the Jenkins job (left hand side pane on the Jenkins job's dashboard). Behind the scene / in Jenkins job's configuration, it calls: release:prepare release:perform goals.
When I'm click on "Perform Maven Release", it does it's job successfully (builds from 1.0.0-SNAPSHOT, run tests && if successful, make changes to pom.xml and put version as 1.0.0 as version ID, perform some more verification and make changes to pom.xml (what maven-release-plugin checks are etc), commit this change in version control, tag it with 1.0.0 as a "TAG" in version control, change pom.xml again to use 1.0.1-SNAPSHOT and commit it, then checkout from that tagged 1.0.0 release version tag which we just created, checkout it under /target/checkout folder, build relase 1.0.0 artifacts (jar/war/pom etc) and finally deploys it to the repository which you'd have mentioned inside ..... ... section.
<distributionManagement>
<repository>
<id>dev-artifactory</id>
<url>http://1.2.3.15:8081/artifactory/libs-release-local/</url>
</repository>
<snapshotRepository>
<id>dev-artifactory</id>
<url>http://1.2.3.15:8081/artifactory/libs-snapshot-local/</url>
</snapshotRepository>
</distributionManagement>
What I need is:
1) How can I make "Perform Maven Release" process to call a deployment to a server once x.x.x release artifacts are generated by the process above and run some Integration tests. This should happen before deployment of artifacts to a binary repository (Artifactory/Nexus) is performed by maven-release-plugin process. i.e. if you are putting artifacts in a release repository, then non-unit tests are also successful (not that artifacts are in libs-release-local repository in Artifactory and Integration tests are yet to be launched.
OR do I need to change ... to use libs-snapshot-local (Artifactory repository) and then run IT tests and finally if those tests are successful, move 1.0.0 release artifacts from libs-stage-local repository to libs-release-local repository.
I know I can put maven-release-plugin related settings in Maven's user's .m2/settings.xml (user global) or at M2_HOME/.m2/settings.xml (global) but at this point, that's not the question.
We have a Jenkins deployment for each environment (dev, qa, prod). We move the same artifacts across all environments using Promoted Builds, Copy Artifact, and Parameterized Trigger plugins. To see how they work together, read this post (How to promote a specific build number from another job in Jenkins?)
As per the release process, instead of Maven Release plugin, use Maven Promote plugin (http://java.jiderhamn.se/2016/05/04/announcing-maven-promote-plugin/) to release the artifact that is already built and tested (there are a lot of articles on maven release plugin's drawbacks). You can still use Jenkins M2 Release Plugin, but in it's configuration, Release goals and options, call mvn release:clean promote:prepare release:prepare instead. For more details: https://github.com/mjiderhamn/promote-maven-plugin/issues/2
Maybe you should consider taking a look at this article here: https://pragmaticintegrator.wordpress.com/2014/05/12/running-the-maven-release-plugin-with-jenkins/
With Jenkins Release plugin you could customize your release workflow to add specific steps once your M2 release is done.

Build Pipeline with Jenkins - M2 Release -> Deployment to JBoss AS

I am using Jenkins as CI environment and I want to have the ability to deploy the build artifacts directly to a JBoss AS 7.1.1 server. For releasing the Maven artifacts I am using the Jenkins M2 Release Plugin.
The project structure of the project which makes problems looks as follows:
artifact-parent-pom
webapp-module
theme-module
The maven goal jboss-as:deploy can only be called on webapp-module.
To deploy the webapp-module to the JBoss server on every build, I added a post-build step calling
mvn jboss-as:deploy
on the sub-module. This works perfectly for standard SNAPSHOT builds, but not for release builds.
When using the Jenkins M2 Release Plugin to release a new artifact version, the version number is already updated to the next SNAPSHOT-version when the post-build step is executed. I tried to deploy the release version directly at the release step, but this doesn't work, hence the goal jboss-as:deploy cannot be called on the parent-pom.
All Jeknins plugins i have found only support older versions of JBoss like
Deploy to container Plugin
JBoss Management Plugin
Is there an easy way to get this working?
I have found a workaround. I made two configurations, one for the SNAPSHOTS and one for the RELEASE builds. At the RELEASE build I added two post-steps both calling the goal version:set on the parent-pom but with different properties. This results in the following post-steps:
mvn newVersion=${MVN_RELEASE_VERSION}
mvn jboss-as:deploy
mvn newVersion=${MVN_DEV_VERSION}

Continuous integration strategy for snapshot dependencies (with Jenkins)

While setting up a Jenkins CI system for the first time, I wonder how to deal with snapshot dependencies and the local Maven repository.
We have an artifact X with dependency Y. Jenkins is configured to build X everytime Y has a commit.
Strategy A (workspace Maven repository):
The local Maven repository is configured to be "local to the workspace". This means that every built job has its own repository. A commit of Y does trigger the build (a "mvn clean install"), but since the repositories of build X and Y are isolated, X uses the last deployed version of Y, not the last commit.
Using this strategy seems useful to detect if all dependencies are also deployed, but it doesn't detect integration issues (broken Y commit breaks X).
Strategy B (common Maven repository):
Jenkins uses a common local Maven repository. A commit of a (broken) Y snapshot triggers the build of X which uses the current Y snapshot, and integration issues are detected. The drawback is, that this doesn't detect if all build dependencies are deployed to the central snapshot repository (because the CI system does have them all installed in the local repository).
Is there a strategy that combines both advantages of A and B?
We ended up using a Strategy C for this:
Strategy C (let Jenkins deploy):
Every job has its local repository local to the workspace like in strategy A. But instead of the default "clean install" goal, Jenkins is configured to do a "-U clean deploy" on every job. So if Y is broken and commited, Jenkins will build it and deploy it to the central snapshot repository. Jenkins detects the build of the dependency Y and builds X with the latest Y snapshot.
Useful for this strategy is - at least with Maven 3 - to run a automatic cleanup job on the central snapshot repository, since there will be a lot of timestamped snapshots.

Resources