Storing path to filesystem trigger in jenkins

I am using the Filesystem Trigger in Jenkins to monitor a folder for any folders named ‘alpha’, if one is found, the job gets kicked off. How can I get the full path to the newly found ‘alpha’ folder in the jenkins pipeline? Is it stored in an environment variable or anything? Thanks.

I tried echoing out the local environment variables for the jenkins job that was triggered but I don’t see anything listed.

Hello @user8675309 and welcome to this community. :wave:

The Filesystem Trigger plugin in Jenkins can be a bit limited in terms of the information it provides to the triggered job. By default, I don’t think it directly provides the full path to the newly found ‘alpha’ folder as an environment variable.

However, I believe you could work around this limitation by using a script within your Jenkins pipeline to find the full path to the ‘alpha’ folder. You could use Groovy to search for the folder recursively within the folder being monitored (not pretty, but…).

pipeline {
    agent any

    stages {
        stage('Find Alpha Folder') {
            steps {
                script {
                    def folderName = 'alpha'
                    def searchPath = '/your/monitored/folder' // Change this to your monitored folder path

                    def alphaFolder = findAlphaFolder(searchPath, folderName)
                    if (alphaFolder != null) {
                        echo "Found 'alpha' folder at: ${alphaFolder}"
                    } else {
                        echo "'alpha' folder not found."

def findAlphaFolder(path, folderName) {
    def file = new File(path)
    if (file.exists() && file.isDirectory()) {
        file.eachDirRecurse { dir ->
            if ( == folderName) {
                return dir
    return null

In this pipeline script, replace /your/monitored/folder with the path to the folder being monitored. The findAlphaFolder function searches for the ‘alpha’ folder recursively within the specified directory. If it finds the ‘alpha’ folder, it returns the full path. Otherwise, it returns null . The result is then printed in the Jenkins build log.

1 Like

Thanks for the response. I ended up doing the same thing, only issue is if multiple ‘alpha’ folders are created then I might find the newest one but not the one that triggered the jenkins job.