<p>My personal opinion is that each deliverable should reside in its own repository. However if one would like to keep the monorepo one could use <a href="https://devops.stackexchange.com/a/6678/210"><code>changeset</code> in conjunction with <code>when</code></a>:</p>

<blockquote>
<pre><code>pipeline {
    agent any
    stages {
        stage('build matchengine') {
            when {
                changeset "**/matchengine/*.*"
            }
            steps {
                echo 'building match engine'
            }
        }
        stage('build posttrade') {
            when {
                changeset "**/posttrade/*.*"
            }
            steps {
                echo 'building post trade'
            }
        }
    }
}
</code></pre>
</blockquote>

<p>or <a href="https://stackoverflow.com/a/49189040/2777965">change the directory in several build stage and build the code inside this directory</a>:</p>

<blockquote>
<pre><code>stage('Build') {
  dir('web_app') {
    sh 'ls'
    sh 'git pull'
  }
}
</code></pre>
</blockquote>

<p>One could also decide to use the <a href="https://jenkins.io/blog/2017/09/25/declarative-1/" rel="nofollow noreferrer">parallel option</a> to ensure that the build times will be shortened:</p>

<blockquote>
<pre><code>/* .. snip .. */
stage('run-parallel-branches') {
  steps {
    parallel(
      a: {
        echo "This is branch a"
      },
      b: {
        echo "This is branch b"
      }
    )
  }
}
/* .. snip .. */
</code></pre>
</blockquote>

<p>Regarding the question:</p>

<blockquote>
  <p>Set up Jenkins job which will trigger task only for repo where PUSH
  has occurred. e.g if my monorepo consist 2 merged repos repo1 and
  repo2 , so if any changes in repo1 should trigger only related task
  for repo1 and likewise for repo2.</p>
</blockquote>

<p>I think that <code>changeset</code> would be most useful: a change will trigger the build, but as a change only occurred in a certain path, only that build will be started.</p>

CC BY-SA 4.0
2019-07-27T09:45:16.243Z
2019-07-27T09:50:30.960Z
2019-07-27T09:50:30.960Z
030
<p>Need bit of help regarding Jenkins CI jobs. I am pretty new to Jenkins world </p>

<p>As per the current set up in our project we have different repositories in GIT and they have web hooks setup with Jenkins to trigger CI jobs in the event of any push. Please note there are separate CI job for different repos.</p>

<p>My requirements :</p>

<ol>
<li>Build a mono repo which will consist all existing repos. ( for test purpose I have created 2 repos and merged them in mono repo ).</li>
<li>Set up Jenkins job which will trigger task only for repo where PUSH has occurred.
e.g if my monorepo consist 2 merged repos repo1 and repo2 , so if any changes in repo1 should trigger only related task for repo1 and likewise for repo2.</li>
</ol>

<p>I’m not sure how could I achieve point 2. Any help?</p>

CC BY-SA 4.0
2019-07-27T09:51:27.847Z
Possible duplicate of [Triggering specific pipeline builds for monorepos in Jenkins](https://devops.stackexchange.com/questions/4355/triggering-specific-pipeline-builds-for-monorepos-in-jenkins)
030
<jenkins>
GIT Monorepo with enterprise Jenkins
Dhiru
# GIT Monorepo with enterprise Jenkins

(Asked by: username_0 on 2019-07-26)

Need bit of help regarding Jenkins CI jobs. I am pretty new to Jenkins world

As per the current set up in our project we have different repositories in GIT and they have web hooks setup with Jenkins to trigger CI jobs in the event of any push. Please note there are separate CI job for different repos.

My requirements :

1. Build a mono repo which will consist all existing repos. ( for test purpose I have created 2 repos and merged them in mono repo ).
2. Set up Jenkins job which will trigger task only for repo where PUSH has occurred.
   e.g if my monorepo consist 2 merged repos repo1 and repo2 , so if any changes in repo1 should trigger only related task for repo1 and likewise for repo2.

I’m not sure how could I achieve point 2. Any help?

**Tags:** jenkins

> **Comments:**
> **username_1**: Possible duplicate of [Triggering specific pipeline builds for monorepos in Jenkins](https://devops.stackexchange.com/questions/4355/triggering-specific-pipeline-builds-for-monorepos-in-jenkins)  

---

## 1 answers

### Answer by username_1 on 2019-07-27. Score: 2

My personal opinion is that each deliverable should reside in its own repository. However if one would like to keep the monorepo one could use changeset in conjunction with when:

pipeline {
    agent any
    stages {
        stage('build matchengine') {
            when {
                changeset "**/matchengine/*.*"
            }
            steps {
                echo 'building match engine'
            }
        }
        stage('build posttrade') {
            when {
                changeset "**/posttrade/*.*"
            }
            steps {
                echo 'building post trade'
            }
        }
    }
}


or change the directory in several build stage and build the code inside this directory:

stage('Build') {
  dir('web_app') {
    sh 'ls'
    sh 'git pull'
  }
}


One could also decide to use the parallel option to ensure that the build times will be shortened:

/* .. snip .. */
stage('run-parallel-branches') {
  steps {
    parallel(
      a: {
        echo "This is branch a"
      },
      b: {
        echo "This is branch b"
      }
    )
  }
}
/* .. snip .. */


Regarding the question:

Set up Jenkins job which will trigger task only for repo where PUSH
  has occurred. e.g if my monorepo consist 2 merged repos repo1 and
  repo2 , so if any changes in repo1 should trigger only related task
  for repo1 and likewise for repo2.

I think that changeset would be most useful: a change will trigger the build, but as a change only occurred in a certain path, only that build will be started.


---

