1

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?

1

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.