I need to check for a specific .exe file in my workspace as part of my pipeline assembly job. I tried using the below Groovy script from my Jenkins file to do the same. But I think the File class, by default, tries to find the workspace directory on the jenkins wizard and fails.
@com.cloudbees.groovy.cps.NonCPS def checkJacoco(isJacocoEnabled) { new File(pwd()).eachFileRecurse(FILES) { it -> if (it.name == 'jacoco.exec' || it.name == 'Jacoco.exec') isJacocoEnabled = true } }
How to access a file system on a slave using Groovy from inside a Jenkins file?
I also tried the code below. But I get the error No such property: build for class: groovy.lang.Binding . Instead, I tried using the manager object. But get the same error.
@com.cloudbees.groovy.cps.NonCPS def checkJacoco(isJacocoEnabled) { channel = build.workspace.channel rootDirRemote = new FilePath(channel, pwd()) println "rootDirRemote::$rootDirRemote" rootDirRemote.eachFileRecurse(FILES) { it -> if (it.name == 'jacoco.exec' || it.name == 'Jacoco.exec') { println "Jacoco Exists:: ${it.path}" isJacocoEnabled = true } }
source share