4
votes

I'm struggling with the Jenkins 2.1 multibranch pipeline, where I have have multiple artifacts building from the same git repository. Some of the artifacts are independent and should trigger builds on changes in their respective directories. Some are dependent and should be triggered by a prior step/build.

The repository has one Jenkinsfile which controls the whole pipeline. The Jenkins Multibranch Pipeline job triggers on all changes (no additional behavoirs).

I don't see how to get the build of artifact A only to trigger on changes in directory dirA.

The Jenkinsfile in the git repo at file:///repopath looks like this:

node(){
  stage 'Build A'
    checkout([$class: 'GitSCM',
      branches: [[name: '*/master']],
      doGenerateSubmoduleConfigurations: false,
      extensions: [
        [$class: 'PathRestriction',
          excludedRegions: '.*',
          includedRegions: 'dirA/.*'],
      [$class: 'RelativeTargetDirectory',
        relativeTargetDir: 'sub']],
        submoduleCfg: [],
        userRemoteConfigs: [[url: 'file:///repopath']]])
    sh './buildA.sh'
}
node(){
   stage 'Build B'
   ...
}
...

This will always trigger the run of buildA.sh :-(

I'm using the folloing plugins:

  • Git client plugin 1.19.6
  • Git plugin 2.4.4
  • Git server plugin 1.6
  • Pipeline 2.0
  • Pipeline: API 2.0
  • Pipeline: Basic Steps 2.0
  • Pipeline: Build Step 2.0
  • Pipeline: Groovy 2.1
  • Pipeline: Input Step 2.0
  • Pipeline: Job 2.1
  • Pipeline: Multibranch 2.3
  • Pipeline: Nodes and Processes 2.0
  • Pipeline: REST API Plugin 1.3
  • Pipeline: SCM Step 2.0
  • Pipeline: Shared Groovy Libraries 2.0
  • Pipeline: Stage Step 2.0
  • Pipeline: Stage View Plugin 1.3
  • Pipeline: Step API 2.0
  • Pipeline: Supporting APIs 2.0
1
Just a comment for now since i didn't try it out myself yet: the nonsnapshot-maven-plugin has a feature that would enable you to start maven with only the modules that were changed: there are more details at kofler.nonblocking.at/2015/01/… the feature i'm talking about comes a bit further down in that article.tobi42

1 Answers

1
votes

how about just doing something like

git log --pretty=format: --name-only -n 15 | sort | uniq

?? if you could determine the number of commits in a build or their hashes, that would answer your question.