@Mig82 has provided a great solution. It has one limitation, though, which is that the folder environment variables it provides are not available in the SCM section of a freestyle build, and possibly in some other sections.
I've found I can get around this using a snippet of groovy:
- In your freestyle job, enable the "Prepare an environment for the
run" section.
- In the "Prepare an environment for the run" section, add the
following code to the "Evaluated Groovy Script" field:
import com.mig82.folders.wrappers.ParentFolderBuildWrapper
import jenkins.tasks.SimpleBuildWrapper
// Create a temporary Context object into which we can load the folder properties.
myContext = new SimpleBuildWrapper.Context()
// Create an object of the class "ParentFolderBuildWrapper".
// This is the class at the heart of the Folder Properties plugin,
// and it implements the code that gets the properties from the folder.
parentFolderBuildWrapper = new ParentFolderBuildWrapper()
// Load the folder properties into our Context object.
parentFolderBuildWrapper.loadFolderProperties(currentJob, myContext)
// Return the map containing the properties.
return myContext.getEnv()