My Organization keeps a single git repository in bitbucket. It hosts multiple projects under the same branch.

I have to automate the build process using Jenkins; I configured a webhooks that invoke on any push to development branch. Now, I have to generate a build based on which sub-directory the changes happened in, e.g. if code was committed to /Microservice2, it will generate build for MS2, _etc.

enter image description here

How does one achieve this using Jenkins?

  • Could you please clarify whether you are using Jenkins pipeline as code, or job dsl? Commented Jun 21, 2020 at 11:32

1 Answer 1


Am assuming you are familiar with Groovy at basic level. Well, you could do the following with Shell scripts too, but I have done something similar using native capabilities of Groovy.

  1. Store changeset by running git log ..., those three dots mean you should go thru' git-log man page to check the options that will list the changed files with folder names.
  2. Iterate thru' the changeset (from item 1) to identify the folder (microservice 2 or 3, 4, so on and so forth).
  3. Once the service is identified, try and set few environment variables that can be reused in other scripts, if you want. Advantage with this approach is, you stand to have access to them until the completion of build.

Hope this helps.

  • could you please share the sample jenkinsfile? Commented Feb 18, 2020 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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