the setup:

      • a multi-module, Jenkinsfile-based, maven project.
      • builds are triggered via notifications from gitlab, manually or by SNAPSHOT builds of dependencies (per checkbox).
      • only the master (and tags) gets deployed to an artifactory.
      • every build uses a temp local maven repository - which is swiped afterwards.
      • so we don't change the version in branches, as their artefacts never leave their sandbox (workplace directory).

      I experience, that the master-build/job triggers (on success) the build of the branches. This makes some kind of sense, as formally the modules depends on the artifact build in the master, but on the other hand, it does not make sense, because the triggered branches-builds/jobs will build these triggering artifacts on their own. 

      I'm looking for some solution to suppress the triggering of builds by other jobs, that build the very same artifacts (at least according to their maven coordinates), the triggered build will build on their own.

      The current workaroud is to change the version in the branches (random or branchname-based), but this seems to me like a hack.

      A possible solution is to substract the set of own-generated artifacts from the set of triggering artifacts when deciding if another job should be executed.

          [JENKINS-54515] master triggers own branches

          which version of the pipeline-maven-plugin are you using?

          Cyrille Le Clerc added a comment - which version of the pipeline-maven-plugin are you using?

          Hi! 

          We are currently on 3.5.9, and tested 3.5.15.  Both with the same effect.

           

          Thorsten Langer added a comment - Hi!  We are currently on 3.5.9, and tested 3.5.15.  Both with the same effect.  

          Is there something I can do to support you understand or reproduce this issue? (I'm still not sure, if it's a bug or a feature request).

          Thorsten Langer added a comment - Is there something I can do to support you understand or reproduce this issue? (I'm still not sure, if it's a bug or a feature request).

          thorsten_langer_sla can you please confirm that the pipeline that is triggered in an undesired manner is using the same pom.xml hosted on the same git repository and that the different branches have the same maven artifact version identifier?

          I want to find a generic way to understand that 2 pipelines relate to the same pom.xml. I would like to avoid finding the relationship going through the discovery of a parent multi branch pipeline.

          Cyrille Le Clerc added a comment - thorsten_langer_sla can you please confirm that the pipeline that is triggered in an undesired manner is using the same pom.xml hosted on the same git repository and that the different branches have the same maven artifact version identifier? I want to find a generic way to understand that 2 pipelines relate to the same pom.xml. I would like to avoid finding the relationship going through the discovery of a parent multi branch pipeline.

          I can confirm this.

          • identical repos in 'master' and any branch.
          • identical pom.xml files in master and usually all branches. (at least in regard to all poms' own project/group|artifactId|version in top level and modules).
          • identical Jenkinsfile (see below)
          • but: different (git) branches.  The distinction per  {{when { buildingTag() } }}  works quite fine
          #!/usr/bin/env groovy
          
          pipeline {
              agent any
          
              tools {
                  maven 'apache-maven-3.3.9'
                  jdk 'jdk1.8.0-latest'
              }
              options {
                  gitLabConnection('weblab.local')
                  gitlabBuilds(builds: ['Java-Build-And-Install'])
                  buildDiscarder logRotator(artifactDaysToKeepStr: '30',
                                            artifactNumToKeepStr: '30', 
                                            daysToKeepStr: '30',
                                            numToKeepStr: '30')
              }
              triggers {
                  gitlab(triggerOnPush: true, 
                      triggerOnMergeRequest: true, 
                      branchFilterType: 'All')
              }
              environment {
                  MAVEN_PROFILES = "-P continuousintegrationProfile -P slaSnapshotsProfile"
              }
          
              stages {
                  stage('Java-Build-And-Install') {
                      steps {
                          gitlabCommitStatus(name: 'Java-Build-And-Install') {
                              withMaven(
                                  mavenLocalRepo: 'local-repo') {
                                  sh "mvn clean install ${MAVEN_PROFILES}"
                              }
                          }
                      }
                  }
                  stage('Java-Deploy') {
                      when { anyOf {
                          branch "master"
                          buildingTag()
                      }}
                      steps {
                          gitlabBuilds(builds: ['Java-Deploy']) {
                              gitlabCommitStatus(name: 'Java-Deploy') {
                                  withMaven(
                                      mavenLocalRepo: 'local-repo') {
                                      sh "mvn deploy -DskipTests=true ${MAVEN_PROFILES}"
                                  }
                              }
                          }
                      }
                  }
              }
              post {
                  cleanup {
                      cleanWs()
                  }
              }
          }
          

          Out current workaround is the following pre-install-stage:
          It gives the accidently-to-be-triggered artifacts in the branches branch-specific names, so they won't be triggered by builds in master.

                                  stage('Java-Rename-Version') {
                                      when { not { anyOf {
                                          branch "master"
                                          buildingTag()
                                      }}}
                                      steps {
                                          gitlabBuilds(builds: ['Java-Rename-Version']) {
                                              gitlabCommitStatus(name: 'Java-Rename-Version') {
                                                  withMaven(
                                                      mavenLocalRepo: "local-repo") {
                                                          sh "mvn versions:set -DskipTests=true -DnewVersion=0.0.0-branch-${env.GIT_BRANCH}-SNAPSHOT -DgenerateBackupPoms=false ${MAVEN_PROFILES}"
                                                  }
                                              }
                                          }
                                      }
                                  }
          

           

          My 2 cents about a generic solution:

          After identifing all to-be-triggered pipelines (per fingerprint), a.k.a. the downstreams, you/one will have to filter out those pipelines, that earlier proved (maybe in their last run) to at least generate all/any of the triggering artifacts. The identification of there (suppressed) triggers should be done by groupId, artifactId and version.

          The bad thing in the branches pipelines is, that the identification of fingerprints of the dependencies/artifacts did obviously happen. Actually a bit too good. But: the fingerprinting of the created artifacts in the branches possibly did not occur, because they where not be released (lack of deploy phase?). So the information to decide to suppress the trigger for a certain branch (or not) might not have been retrieved in the branches yet.

           

          Thorsten Langer added a comment - I can confirm this. identical repos in 'master' and any branch. identical pom.xml files in master and usually all branches. (at least in regard to all poms' own project/group|artifactId|version in top level and modules). identical Jenkinsfile (see below) but: different (git) branches.  The distinction per   {{when { buildingTag() } }}  works quite fine #!/usr/bin/env groovy pipeline { agent any tools { maven 'apache-maven-3.3.9' jdk 'jdk1.8.0-latest' } options { gitLabConnection( 'weblab.local' ) gitlabBuilds(builds: [ 'Java-Build-And-Install' ]) buildDiscarder logRotator(artifactDaysToKeepStr: '30' , artifactNumToKeepStr: '30' , daysToKeepStr: '30' , numToKeepStr: '30' ) } triggers { gitlab(triggerOnPush: true , triggerOnMergeRequest: true , branchFilterType: 'All' ) } environment { MAVEN_PROFILES = "-P continuousintegrationProfile -P slaSnapshotsProfile" } stages { stage( 'Java-Build-And-Install' ) { steps { gitlabCommitStatus(name: 'Java-Build-And-Install' ) { withMaven( mavenLocalRepo: 'local-repo' ) { sh "mvn clean install ${MAVEN_PROFILES}" } } } } stage( 'Java-Deploy' ) { when { anyOf { branch "master" buildingTag() }} steps { gitlabBuilds(builds: [ 'Java-Deploy' ]) { gitlabCommitStatus(name: 'Java-Deploy' ) { withMaven( mavenLocalRepo: 'local-repo' ) { sh "mvn deploy -DskipTests= true ${MAVEN_PROFILES}" } } } } } } post { cleanup { cleanWs() } } } Out current workaround is the following pre-install-stage: It gives the accidently-to-be-triggered artifacts in the branches branch-specific names, so they won't be triggered by builds in master. stage( 'Java-Rename-Version' ) { when { not { anyOf { branch "master" buildingTag() }}} steps { gitlabBuilds(builds: [ 'Java-Rename-Version' ]) { gitlabCommitStatus(name: 'Java-Rename-Version' ) { withMaven( mavenLocalRepo: "local-repo" ) { sh "mvn versions:set -DskipTests= true -DnewVersion=0.0.0-branch-${env.GIT_BRANCH}-SNAPSHOT -DgenerateBackupPoms= false ${MAVEN_PROFILES}" } } } } }   My 2 cents about a generic solution: After identifing all to-be-triggered pipelines (per fingerprint), a.k.a. the downstreams, you/one will have to filter out those pipelines, that earlier proved (maybe in their last run) to at least generate all/any of the triggering artifacts. The identification of there (suppressed) triggers should be done by groupId, artifactId and version. The bad thing in the branches pipelines is, that the identification of fingerprints of the dependencies/artifacts did obviously happen. Actually a bit too good. But: the fingerprinting of the created artifacts in the branches possibly did not occur, because they where not be released (lack of deploy phase?). So the information to decide to suppress the trigger for a certain branch (or not) might not have been retrieved in the branches yet.  

          Cyrille Le Clerc added a comment - - edited
          • Please test beta version 3.6.4-beta-1
          • To verify, please enable logs org.jenkinsci.plugins.pipeline.maven.listeners.DownstreamPipelineTriggerRunListener at the FINE level and see message such as
            [withMaven] downstreamPipelineTriggerRunListener - Skip triggering my-multi-jar-project » PR-1 for 
            MavenArtifact{com.example.multi-jar:shared-core:jar:0.0.1-SNAPSHOT(version: 0.0.1-20181202.224248-35, snapshot:true) } 
            because it generates artifact with same groupId:artifactId 
            MavenArtifact{com.example.multi-jar:shared-core:jar:0.0.1-20181202.224107-34(version: 0.0.1-SNAPSHOT, snapshot:true) }
            
          • Please ensure that you use a MySQL database instead of the embedded H2 database as documented in "Using a MySQL Database"

          To download 3.6.4-beta-1: https://github.com/jenkinsci/pipeline-maven-plugin/releases/tag/pipeline-maven-3.6.4-beta-1

          Cyrille Le Clerc added a comment - - edited Please test beta version 3.6.4-beta-1 To verify, please enable logs org.jenkinsci.plugins.pipeline.maven.listeners.DownstreamPipelineTriggerRunListener at the FINE level and see message such as [withMaven] downstreamPipelineTriggerRunListener - Skip triggering my-multi-jar-project » PR-1 for MavenArtifact{com.example.multi-jar:shared-core:jar:0.0.1-SNAPSHOT(version: 0.0.1-20181202.224248-35, snapshot:true) } because it generates artifact with same groupId:artifactId MavenArtifact{com.example.multi-jar:shared-core:jar:0.0.1-20181202.224107-34(version: 0.0.1-SNAPSHOT, snapshot:true) } Please ensure that you use a MySQL database instead of the embedded H2 database as documented in " Using a MySQL Database " To download 3.6.4-beta-1: https://github.com/jenkinsci/pipeline-maven-plugin/releases/tag/pipeline-maven-3.6.4-beta-1

          Hello!  

           Thank you for your efforts so far.  It might take a few more days for us to test, but I will answer you here.

           

          Thorsten Langer added a comment - Hello!    Thank you for your efforts so far.  It might take a few more days for us to test, but I will answer you here.  

          Cyrille Le Clerc added a comment - Thanks thorsten_langer_sla

          Shipped in v3.6.4

          Cyrille Le Clerc added a comment - Shipped in v3.6.4

          dan tran added a comment - - edited

          Unfortunately, my downstream pipelines do generate the same artifact ( just not deploy to  maven repo). am I toasted?

          Use case:  one main pipeline ( mvn deploy) triggers a number of pipeline using same source to run integrations in parallel ( mvn install). See 

          1. JENKINS-53382

          dan tran added a comment - - edited Unfortunately, my downstream pipelines do generate the same artifact ( just not deploy to  maven repo). am I toasted? Use case:  one main pipeline ( mvn deploy) triggers a number of pipeline using same source to run integrations in parallel ( mvn install). See  JENKINS-53382

          dantran we brainstormed with aheritier and we felt that a reasonable default behaviour would be to not trigger pipelines that work on the same pom.xml. The implementation we chose, as we don't capture for the moment the pom.xml details (1), is to not trigger pipeline that generate the artifact that would be the reason of the trigger.

          This solution is fixing all the problems of multi-module Maven projects with multiple git branches but is unfortunately excluding your scenario.

          How frequent in your organisation is this scenario of chaining pipeline using same pom.xml? How many Maven apps do you build? How many Maven pipelines do you have? How many of such chain of pipelines do you have?
          Did you consider merging these chained pipelines in a single pipeline job? Did you face problems trying this?

          (1) SCM details + path in the SCM repo + introducing a POM entity in our data model between the builds and the dependency

          Cyrille Le Clerc added a comment - dantran we brainstormed with aheritier and we felt that a reasonable default behaviour would be to not trigger pipelines that work on the same pom.xml. The implementation we chose, as we don't capture for the moment the pom.xml details (1), is to not trigger pipeline that generate the artifact that would be the reason of the trigger. This solution is fixing all the problems of multi-module Maven projects with multiple git branches but is unfortunately excluding your scenario. How frequent in your organisation is this scenario of chaining pipeline using same pom.xml? How many Maven apps do you build? How many Maven pipelines do you have? How many of such chain of pipelines do you have? Did you consider merging these chained pipelines in a single pipeline job? Did you face problems trying this? (1) SCM details + path in the SCM repo + introducing a POM entity in our data model between the builds and the dependency

          Fixed in 3.6.4

          Cyrille Le Clerc added a comment - Fixed in 3.6.4

          dan tran added a comment -

           

          We have one large repo with 400+ maven modules including both production and integration test sources.  Main repo build (~60min)  does build integration test modules abut not running them.  We also have many wrapper repos clone the main repo at build time and run

            * subset of integration tests at each repo ( ie main build trigger a number of parallel integration test builds

            * Platform sanity builds ( windows, etc)

           

          Merge them into a single pipeline are big, complex, and long.

          is there a way to disable maven pipeline event listener after we clone the main repo at the test pipelines?

           

          dan tran added a comment -   We have one large repo with 400+ maven modules including both production and integration test sources.  Main repo build (~60min)  does build integration test modules abut not running them.  We also have many wrapper repos clone the main repo at build time and run   * subset of integration tests at each repo ( ie main build trigger a number of parallel integration test builds   * Platform sanity builds ( windows, etc)   Merge them into a single pipeline are big, complex, and long. is there a way to disable maven pipeline event listener after we clone the main repo at the test pipelines?  

          dan tran added a comment - - edited

          on the second thought, i am going to create a delegate job to invoke my sub jobs directly.  So we good ( a --> b --> delegate --> c,e,f   etc )

          but, it would be great to have this fix  https://issues.jenkins-ci.org/browse/JENKINS-53382

           

           

          dan tran added a comment - - edited on the second thought, i am going to create a delegate job to invoke my sub jobs directly.  So we good ( a --> b --> delegate --> c,e,f   etc ) but, it would be great to have this fix    https://issues.jenkins-ci.org/browse/JENKINS-53382    

          We can confirm, that the triggering from master to branches does not occur anymore.

          We tested this using the standard DB, because changing the DB to the MySQL version mentioned above was a bit tricky in our setup.

          In the log-file we cannot see any of these skip-messages you expected.

           

          Please note, that the branches (jobs) are still listed as downstream jobs of master job in the maven tab in the classic website.

           

           Thank you very much!

          Thorsten Langer added a comment - We can confirm, that the triggering from master to branches does not occur anymore. We tested this using the standard DB, because changing the DB to the MySQL version mentioned above was a bit tricky in our setup. In the log-file we cannot see any of these skip-messages you expected.   Please note, that the branches (jobs) are still listed as downstream jobs of master job in the maven tab in the classic website.    Thank you very much!

            cleclerc Cyrille Le Clerc
            thorsten_langer_sla Thorsten Langer
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: