# Pipeline scoped to its subdirectory/branch in a (mono)repo

**URL:** <https://community.jenkins.io/t/pipeline-scoped-to-its-subdirectory-branch-in-a-mono-repo/4440>\
**Category:** Ask a question\
**Created:** [November 5, 2022, 10:32pm UTC](https://community.jenkins.io/t/pipeline-scoped-to-its-subdirectory-branch-in-a-mono-repo/4440 "2022-11-05T22:32:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![firmsoil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/firmsoil/32/2641_2.png) [@firmsoil](https://community.jenkins.io/u/firmsoil)\
**Post date:** [November 5, 2022, 10:32pm UTC](https://community.jenkins.io/t/pipeline-scoped-to-its-subdirectory-branch-in-a-mono-repo/4440/1 "2022-11-05T22:32:40Z")

</div>

What if any is Jenkins’ equivalent to the following GitHub Actions featureset.

When using the push and pull\_request events, you can configure a pipeline/workflow to run based on what file paths are changed. Path filters are not evaluated for pushes of tags.

[https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onpushpull\_requestpull\_request\_targetpathspaths-ignore](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onpushpull_requestpull_request_targetpathspaths-ignore)

When using the pull\_request and pull\_request\_target events, you can configure a pipeline/workflow to run only for pull requests that target specific branches.

[https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onpull\_requestpull\_request\_targetbranchesbranches-ignore](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onpull_requestpull_request_targetbranchesbranches-ignore)

Looks like the closest equivalent I can find is following which is available not available for scripted pipeline.

changeset

Execute the stage if the build’s SCM changeset contains one or more files matching the given pattern. Example: `when { changeset "**/*.js" }`

The optional parameter `comparator` may be added after an attribute to specify how any patterns are evaluated for a match: `EQUALS` for a simple string comparison, `GLOB` (the default) for an ANT style path glob case insensitive, this can be turned off with the `caseSensitive` parameter, or `REGEXP` for regular expression matching. For example: `when { changeset pattern: ".TEST\\.java", comparator: "REGEXP" }` **or `when { changeset pattern: "`** `*/*TEST.java", caseSensitive: true }`

---

<div class="post-metadata">

**Author:** ![criztovyl](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/criztovyl/32/2642_2.png) [@criztovyl](https://community.jenkins.io/u/criztovyl)\
**Post date:** [November 6, 2022, 11:06am UTC](https://community.jenkins.io/t/pipeline-scoped-to-its-subdirectory-branch-in-a-mono-repo/4440/2 "2022-11-06T11:06:39Z")

</div>

You did not really ask a question, are you looking for guidance how to implement `when { changset }` with scripted Pipeline?

Is there a specific reason you are looking for scripted pipeline?  
Note you can use the `script{}` esacpe-hatch in many places in declarative Pipeline.

---

<div class="post-metadata">

**Author:** ![firmsoil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/firmsoil/32/2641_2.png) [@firmsoil](https://community.jenkins.io/u/firmsoil)\
**Post date:** [November 6, 2022, 4:48pm UTC](https://community.jenkins.io/t/pipeline-scoped-to-its-subdirectory-branch-in-a-mono-repo/4440/3 "2022-11-06T16:48:48Z")

</div>

Thanks much for responding. Well, is there a native solution for jenkins users who are invested in scripted pipeline (see reasons below) and do not plan to migrate to the declarative pipeline.

> **[Pipeline Syntax](https://www.jenkins.io/doc/book/pipeline/syntax/#compare)**
>
> Jenkins – an open source automation server which enables developers around the world to reliably build, test, and deploy their software

“Jenkins has long shipped with an embedded Groovy engine to provide advanced scripting capabilities for admins and users alike. The Groovy learning-curve isn’t typically desirable for all members of a given team, so Declarative Pipeline was created to offer a simpler and more opinionated syntax for authoring Jenkins Pipeline.  
:  
**As it is a fully-featured programming environment, Scripted Pipeline offers a tremendous amount of flexibility and extensibility to Jenkins users.** Both are fundamentally the same Pipeline sub-system underneath.”

---

<div class="post-metadata">

**Author:** ![criztovyl](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/criztovyl/32/2642_2.png) [@criztovyl](https://community.jenkins.io/u/criztovyl)\
**Post date:** [November 6, 2022, 6:20pm UTC](https://community.jenkins.io/t/pipeline-scoped-to-its-subdirectory-branch-in-a-mono-repo/4440/4 "2022-11-06T18:20:15Z")

</div>

Scripted Pipeline currently has no built-in `when` step, but you can hook into the API the declarative Pipeline is using, see [jenkins - Jenkinsfile - Conditional stage execution in the Script Pipeline syntax - Stack Overflow](https://stackoverflow.com/a/50372428).

> Per the comments on JENKINS-47286, it doesn’t sound like adding when support to Scripted Pipeline will happen. As a potential workaround, there is a shared library implementing the when statement for scripted pipelines: github: comquent/imperative-when

The `when { changeset }` you can emulate using `git` CLI and [`GIT_PREVIOUS_(SUCCESSFUL_)COMMIT`](https://plugins.jenkins.io/git/#plugin-content-commit-variables).

---

<div class="post-metadata">

**Author:** ![firmsoil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/firmsoil/32/2641_2.png) [@firmsoil](https://community.jenkins.io/u/firmsoil)\
**Post date:** [November 6, 2022, 7:17pm UTC](https://community.jenkins.io/t/pipeline-scoped-to-its-subdirectory-branch-in-a-mono-repo/4440/5 "2022-11-06T19:17:23Z")

</div>

Thanks very much for your help. Much appreciated.
