-1

I am using the FileSystem trigger to monitor whether the code in a folder changed (from git repo)

My thought is

  1. use normal Poll SCM every 2 minutes
  2. check the actual downloaded source folder in question for changes after step 1 polls the every 2 minutes.

Questions:

  1. Is the flow correct? Should it poll SCM every 2 minutes, and then the actual folder every 2 minutes? Should it directly poll the folder in the repo on bitbucket/github? Currently the build is being built every time the project fires - it bypasses the folder check.

  2. I tried setting the folder path to %WORKSPACE%/MyProjectToMonitorFolder and the [FSTrigger] - Monitor folder logs said that it could not find the folder. If I hardcode the actual full folder path as in the image then the folder and changes are found. How can I incorporate %WORSKPACE% into the folder path?

enter image description here

Peter PitLock
  • 1,823
  • 7
  • 34
  • 71
  • What exactly are you trying to achieve? do you want a trigger when the source code has changes or when the filesystem has changed? usually these two triggers don't go together and serve very different needs. – Noam Helmer Jul 08 '21 at 16:32
  • The need is to trigger a build only if the contents in a specific folder has changed. My uninformed thought was that the Poll SCM schedule will still check if the repo changed, and then the FS Trigger will look at the specific folder which was just updated from the FSTrigger. – Peter PitLock Jul 09 '21 at 07:37
  • 1
    See [This Answer](https://stackoverflow.com/questions/29780647/jenkins-and-git-monitor-specific-folder-on-any-branch) you can configure the git pull SCM to pull changes only when they are done to a specific folder - that should do the trick for you. – Noam Helmer Jul 09 '21 at 07:46
  • 1
    Thank you for pointing me to the default Jenkins behaviour - works great – Peter PitLock Jul 09 '21 at 10:22

1 Answers1

1

Both triggers serve very different use cases and usually don't go together. I assume what you want to achieve is a trigger to your job that will run it whenever a specific folder has changes in your Git repository.
You can achieve it by first configuring you SCM Git build stage to only monitor a specific folder in your repository, it will eliminate the need for using the file system trigger as it will only trigger the job when the configured folders have changed. You can find more info in the Official Documentation under the Polling ignores commits in certain paths section.
You can also check out This Answer for more info.

In addition it is highly recommended to move from a scheduled SCM pulling mechanism to a hook based Git trigger that will trigger your job whenever new code is pushed to the repository and will avoid the need to constantly check for changes, see This This Answer for more info on the git hooks configuration.
Furthermore every major Git repository manger (GitHub, Bitbucket, Gitlab...) has dedicated integration Jenkins plugins for git hooks and other operations - so you can use one of them to make your integration easy.

Noam Helmer
  • 5,310
  • 1
  • 9
  • 29