According to the github action documentation, it should work in the same workflow using multiple paths.

If you also use the paths-filter action you can get to the result you want with something like this:

Example:

name: Trigger Jenkins Build [ Build-Portal ]
on:
  push:
    branches: [ develop ]
    paths: 
       - 'frontend/**'
       - 'backend/**'
    types: [closed]
jobs:
  build:
    name: Triggering Jenkins Build [ Build-Portal ]
    runs-on: ubuntu-latest
    if: github.event.pull_request.merged == true
    steps:
      - uses: dorny/paths-filter@v2
        id: changes
        with:
           filters: |
              backend:
                - 'backend/**'
              frontend:
                - 'frontend/**'
    - name: Trigger Build-Portal FRONTEND
      # run only if some file in 'frontend' folder was changed
      if: steps.changes.outputs.frontend == 'true'
      uses: actions/trigger-jenkins@develop
      with:
        ...
        job_name: "Build-Portal"
        job_params: '{"FRESH_BUILD":"True", "UI":"True", "BUILD_BRANCH":"develop", "DEPLOY_DEV":"True"}'
        ...
     - name: Trigger Build-Portal BACKEND
      # run only if some file not 'backend' folder was changed
      if: steps.changes.outputs.backend == 'true'
      uses: actions/trigger-jenkins@develop
      with:
        ...
        job_name: "Build-Portal"
        job_params: '{"FRESH_BUILD":"True", "API":"True", "BUILD_BRANCH":"develop", "DEPLOY_DEV":"True"}'
        ...
Answer from GuiFalourd on Stack Overflow
Top answer
1 of 2
16

According to the github action documentation, it should work in the same workflow using multiple paths.

If you also use the paths-filter action you can get to the result you want with something like this:

Example:

name: Trigger Jenkins Build [ Build-Portal ]
on:
  push:
    branches: [ develop ]
    paths: 
       - 'frontend/**'
       - 'backend/**'
    types: [closed]
jobs:
  build:
    name: Triggering Jenkins Build [ Build-Portal ]
    runs-on: ubuntu-latest
    if: github.event.pull_request.merged == true
    steps:
      - uses: dorny/paths-filter@v2
        id: changes
        with:
           filters: |
              backend:
                - 'backend/**'
              frontend:
                - 'frontend/**'
    - name: Trigger Build-Portal FRONTEND
      # run only if some file in 'frontend' folder was changed
      if: steps.changes.outputs.frontend == 'true'
      uses: actions/trigger-jenkins@develop
      with:
        ...
        job_name: "Build-Portal"
        job_params: '{"FRESH_BUILD":"True", "UI":"True", "BUILD_BRANCH":"develop", "DEPLOY_DEV":"True"}'
        ...
     - name: Trigger Build-Portal BACKEND
      # run only if some file not 'backend' folder was changed
      if: steps.changes.outputs.backend == 'true'
      uses: actions/trigger-jenkins@develop
      with:
        ...
        job_name: "Build-Portal"
        job_params: '{"FRESH_BUILD":"True", "API":"True", "BUILD_BRANCH":"develop", "DEPLOY_DEV":"True"}'
        ...
2 of 2
3

I don't see the reason behind this complexity. Just use 2 YML files

frontend.yml => this is where you put path condition to match frontend path

on:
 push:
  branches: [ develop ]
  paths: 
   - 'frontend/**'

backend.yml => this is where you put path condition to match backend path

on:
 push:
  branches: [ develop ]
  paths: 
   - 'backend/**'

Both files will be evaluated everytime a push is done and GH will decide which flow to run.

You can always use a default yml file to run anyway whenever any change occurs outside these paths

🌐
GitHub
docs.github.com › actions › using-workflows › workflow-syntax-for-github-actions
Workflow syntax for GitHub Actions - GitHub Docs
The name of the workflow. GitHub displays the names of your workflows under your repository's "Actions" tab. If you omit name, GitHub displays the workflow file path relative to the root of the repository.
Discussions

How does on.paths really work?
We make heavy use of on: push: paths: - "something/**" For scoping Workflows related to some sub-component of our monorepository to only run when code within that component has changed. W... More on github.com
🌐 github.com
5
6
May 23, 2021
How to define a trigger for such GitHub Action based on branch and path?
You can find a good explanation on how to trigger a GH action in their docs , but as a short TLDR: on: pull_request: paths: - "samples/start-projects/**" 2. you could achieve this in two different ways: by specifying the branches in the same way as the paths above on: pull_request: branches: - "release-*" - "renovate-*" or by passing an if statement to the jobs where you check if the branch name is what you like jobs: lint: if: ${{ startsWith(github.event.ref, "renovate") }} But I'm not sure how to check for both at the same time to be honest. In my GH Actions writing so far I had to check for either the one or the other, but never both. If you can solve this problem, let me know! More on reddit.com
🌐 r/github
2
3
September 26, 2023
Path to action in the same repository as workflow
I have a repository with a rails app. The repository has its own action to run tests in a docker container. The workflow’s path would be /.github/workflows/main.yml while the action’s path would be /.github/actions/automatic-tests/action.yml. More on github.com
🌐 github.com
25
49
What’s the best way to trigger a GitHub Actions workflow only when specific files or folders change?
I’ve tried using paths in the on.push trigger, but I’m not sure if I’m doing it optimally or if it works with pull requests too. What’s the best practice for this use case? Also, how does it behave with file deletions or renames? ... Beta Was this translation helpful? Give feedback. ... This is about GitHub Actions... More on github.com
🌐 github.com
2
1
🌐
GitHub
docs.github.com › actions › using-workflows › triggering-a-workflow
Triggering a workflow - GitHub Docs
If you define neither tags/tags-ignore or branches/branches-ignore, the workflow will run for events affecting either branches or tags. If you define both branches/branches-ignore and paths/paths-ignore, the workflow will only run when both filters are satisfied.
🌐
GitHub
github.com › marketplace › actions › paths-changes-filter
Paths Changes Filter · Actions · GitHub Marketplace · GitHub
# Default: none list-files: '' # Relative path under $GITHUB_WORKSPACE where the repository was checked out. working-directory: '' # Personal access token used to fetch a list of changed files # from GitHub REST API. # It's only used if action is triggered by a pull request event.
🌐
DEV Community
dev.to › jajera › understanding-github-actions-working-directory-550o
Understanding GitHub Actions Working Directory - DEV Community
January 7, 2025 - steps: - name: Extract Tag Name run: echo "Tag: ${GITHUB_REF#refs/tags/}" You can use this dynamic value to construct paths: steps: - name: Run with Dynamic Tag Path run: echo "Using path /home/runner/work/_actions/my-actions/my-actions/v1/"
🌐
Microsoft Learn
learn.microsoft.com › en-us › training › paths › github-actions
Automate your workflow with GitHub Actions Part 1 of 2 - Training | Microsoft Learn
In this learning path, you'll: Plan automation of your software development life cycle with GitHub Actions workflows. Use GitHub Actions to automatically build your application. Use GitHub Script to interact with the GitHub API.
Find elsewhere
🌐
GitHub
github.com › dorny › paths-filter
GitHub - dorny/paths-filter: Conditionally run actions based on files modified by PR, feature branch or pushed commits · GitHub
3 weeks ago - on: push: branches: # Push to following branches will trigger the workflow - master - develop - release/** jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 # Some action that modifies files tracked by git (e.g. code linter) - uses: johndoe/some-action@v1 # Filter to detect which files were modified # Changes could be, for example, automatically committed - uses: dorny/paths-filter@v4 id: filter with: base: HEAD filters: ... # Configure your filters ... - uses: dorny/paths-filter@v4 id: filter with: # Path to file where filters are defined filters: .github/filters.yaml
Starred by 3K users
Forked by 362 users
Languages   TypeScript 99.4% | JavaScript 0.6%
🌐
GitHub
github.com › orgs › community › discussions › 78711
Allow access to env vars in path filter · community · Discussion #78711
env: TARGET_DIR: '2023/1-1-trebuchet' on: pull_request: paths: - '${{ env.TARGET_DIR }}/**' workflow_dispatch: Beta Was this translation helpful? Give feedback. ... There was an error while loading. Please reload this page. Something went wrong. There was an error while loading. Please reload this page. ... GitHub Actions does not support using environment variables in the paths filter of the on keyword.
🌐
GitHub
github.com › orgs › community › discussions › 164673
What’s the best way to trigger a GitHub Actions workflow only when specific files or folders change? · community · Discussion #164673
I’ve tried using paths in the on.push trigger, but I’m not sure if I’m doing it optimally or if it works with pull requests too. What’s the best practice for this use case? Also, how does it behave with file deletions or renames? ... Beta Was this translation helpful? Give feedback. ... This is about GitHub Actions' path filtering capabilities, specifically for monorepo workflows.
🌐
Edwardthomson
edwardthomson.com › blog › github_actions_10_path_triggers
GitHub Actions Day 10: Path Triggers
In this case, we want to run when anything in the docs directory is changed in the master branch. We can use a wildcard as part of our path filter:
🌐
GitHub
github.com › marketplace › actions › path-filter
Path Filter · Actions · GitHub Marketplace · GitHub
And, in this action's run input, access them with Bash variables like $GITHUB_ACTION_PATH/files.json, but note that the Bash script in run input will not be executed if there are no files after filtering.
Top answer
1 of 1
4

The difference in the $PATH variable between your GitHub Actions workflow and your local terminal might be due to differences in the shell environment.

In a local terminal, the $PATH variable is often set in a shell configuration file like .bashrc, .bash_profile, or .zshrc. These files are loaded when you start a new shell session. The $PATH variable is used to define the directories where the system should look for executable files. Different configurations or initialization scripts can lead to different values of $PATH.

In a GitHub Actions workflow, especially when using SSH or other remote connection methods, the shell environment may be non-interactive, which means it doesn't load the same configuration files that your local interactive shell does. Instead, it may use system-wide or default environment settings.

Here are a few steps you can take to investigate and potentially resolve this issue:

Explicitly Set $PATH: In your GitHub Actions workflow, you can explicitly set the $PATH variable to match your local environment. For example, you can add the following command at the beginning of your workflow:

> $GITHUB_ENV">
- name: Set PATH
  run: echo "export PATH=\$PATH:/usr/local/bin:/your/custom/path" >> $GITHUB_ENV

Replace :/usr/local/bin:/your/custom/path with the paths you want to include.

Check Shell Initialization Files: Review the shell initialization files on the remote server (e.g., .bashrc, .bash_profile, .zshrc) to see if any customizations to the $PATH are present. Modify these files as needed.

Interactive vs. Non-Interactive Shell: Ensure that any modifications to the $PATH are applied in both interactive and non-interactive shell sessions. Some shell configuration files are only loaded in interactive sessions, so you may need to make these changes more globally in your server environment settings.

Debug Output: Add debug output to your GitHub Actions workflow to print the $PATH variable and other environment information to help diagnose the differences:

- name: Debug Environment
  run: |
    echo "PATH: $PATH"
    echo "SHELL: $SHELL"
  shell: bash

This will allow you to see the values of these variables during your workflow run.

By following these steps, you can ensure that the $PATH variable in your GitHub Actions workflow matches your local environment and functions as expected.

🌐
GitHub
github.com › orangain › understand-github-actions-on-paths
GitHub - orangain/understand-github-actions-on-paths: Example repository to understand how does list of changed files is generated in GitHub Actions.
Example repository to understand how does list of changed files is generated in GitHub Actions. Also investigates Travis CI's TRAVIS_COMMIT_RANGE and CircleCI's pipeline.git.revision and pipeline.git.base_revision. ... Each commit creates a new file and add a new workflow whose trigger of on.push.paths and on.pull_request.paths is a filter which exactly match the newly created file.
Author   orangain
🌐
CICube
cicube.io › home › workflow hub › how to conditionally run github actions based on modified files in pull requests or commits?
How to conditionally run GitHub Actions based on modified files in pull requests or commits? - Workflow Hub - CI Cube
May 8, 2024 - Automated this through workflows in GitHub Actions to detect changes against a specified base branch (like develop) in feature branches. This way, testing and integration would be smoother in that CI tasks would trigger only relevant changes. on: push: branches: - feature/** jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 20 - uses: dorny/paths-filter@v3 id: filter with: base: develop # Change detection against merge-base with this branch filters: ...