I had a poke around in the folder plugin - source code diving results below.
The classes of interest are FolderCredentialsProvider, AbstractFolder, and FolderCredentialsProperty.
When the provider is asked for credentials, it tests if the itemGroup is an AbstractFolder (or walks up the tree till it finds the nearest parent that is an AbstractFolder). Then it gets the credentials from the AbstractFolder's FolderCredentialsProperty (which just seems to be a holder class). The credentials are a plain old in-memory Map<domain, credentials>. Then it returns the credentials list, optionally filtered by domain.
It looks like the AbstractFolder is responsible for persistence of its components, on the Jenkins master's disk. The persistence structure looks like
- jobs/
- foo/ (a normal job)
- <folder>
- config.xml (folder-scoped config, including the serialized credentials)
- jobs/
- bar/ (a folder-scoped job)
Great suggestion, and indeed something we are starting to think about.
Do you happen to have any examples of plugins that take folder-scoped configuration? This would help to get started.