ajayz
ajayz

Reputation: 21

Dependent Job doesn't get triggered when SNAPSHOT is built

I have a project (B,C,D) that depends on a Common-project(A). When A is built B,C,D should be triggered using pipelines. All builds are successful.

Project-A is producing a JAR, which is not published anywhere else than locally (~/.m2/...)

I normally use Jenkinsfiles, but for now I've also setup minimal pipeline-jobs with the code directly in Jenkins while trying to get the triggering to work.

Below is the minimal pipeline jobs I've created for testing.

For all projects I've ticked "Build whenever a SNAPSHOT dependency is built"

In the build logs I can see this for both projects: [INFO] [jenkins-event-spy] Generated /var/lib/jenkins/workspace/ProjectName@tmp/withMavend4286f3f/maven-spy-20190411-121907-5107444902202263660415.log

Project A pipeline

node{
  stage ('Build'){
      git branch: 'master', credentialsId: 'theID', url: '[email protected]:ORG/PROJECT-A.git'
     withMaven(
        maven: 'Maven_3_6_0',
        jdk: 'Java1.8'

        ) {
          sh "mvn clean install"
    }
  }
}

Project B pipeline

node{
    stage ('Build'){
      git branch: 'master', credentialsId: 'theID', url: '[email protected]:ORG/PROJECT-B.git'
     withMaven(
        maven: 'Maven_3_6_0',
        jdk: 'Java1.8'
        ) {
            sh "mvn clean install"
        }
    }
}

Project B pom.xml dependency declaration

        <dependency>
            <groupId>com.myorg</groupId>
            <artifactId>projecta</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

I cannot figure out what else is needed to get project B triggered whenever A is built.

Upvotes: 2

Views: 2059

Answers (2)

sedstef
sedstef

Reputation: 36

I think the problem is that method recordGeneratedArtifact is called with the timestamp ("version:1.0-20191009.204621-22") version instead of "-SNAPSHOT", so the listUpstream and listDownstream queries cannot return a result...

Upvotes: 1

Cyrille Le Clerc
Cyrille Le Clerc

Reputation: 111

Please see the Pipeline Maven Plugin FAQ > My downstream pipelines don't get triggered even if I use "Build whenever a SNAPSHOT dependency is built"

To configure the Jenkins Pipeline Maven integration to trigger downstream pipelines on mvn install:

  • Either change the global configuration:

    • Navigate to "Manage Jenkins / Global Tools Configuration"
    • Click on "Add Publisher" and select "Pipeline Graph Publisher"
    • In the section "Downstream Pipeline Triggers", change the the "Maven lifecycle threshold" from "deploy" to "install" Pipeline Maven Plugin > Global Configuration > Trigger Downstream Pipelines > Maven lifecycle threshold
  • Or in the script of the upstream pipeline, configure withMaven(options: [pipelineGraphPublisher(lifecycleThreshold: 'install')]) {...}

Please also don't forget on the downstream pipelines (project B), to enable "Build whenever a SNAPSHOT dependency is built" (properties([pipelineTriggers([snapshotDependencies()])]))

Upvotes: 2

Related Questions