David Bensoussan
David Bensoussan

Reputation: 3205

How to list folders containing a file on jenkins pipeline?

I'm trying to list folders containing a certain file on jenkins and use later this array.

I read about findFiles but I can't find a way to use it in this situation.

The finality is that I need to cd to those folders in a loop and perform some actions.

I have only one jenkins where everything is running

Use case:

I have a workspace in which I have packages. I need to run some commands in some folders, I can't do it from the root of y workspace. They may be in subfolders or subsubfolders. The way I can identify a package is when it contains a package.xml (on ROS). Also I don't have any command to list their paths

Upvotes: 2

Views: 4429

Answers (2)

towel
towel

Reputation: 2214

def packageDirs = findFiles(glob: '**/package.xml')
    .findAll { f -> !f.directory }
    .collect{ f -> f.path.replace('/', '\\') - ~/\\[^\\]+$/ }

packageDirs.each { d ->
    dir(d) {
        // Process each package here
    }
}

Upvotes: 1

Siddhant Mishra
Siddhant Mishra

Reputation: 508

If nothing else is working then you can try running a normal linux command like:

folders = sh(
             script: "locate myfile",
             returnStdout: true
                                )

Then split this to form an array and use the value like :

folders.split("\n")[1]

Upvotes: 2

Related Questions