-
Notifications
You must be signed in to change notification settings - Fork 830
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Don't destroy credentials when re-creating folders
As noted in JENKINS-44681, any credentials on folders are lost when re-creating folders, as we don't merge the existing credentials with the newly created folder. To do this, we need to find any instances of `FolderCredentialsProvider.FolderCredentialsProperty` in the `Folder`'s and if present, merge the credentials. We need to promote our dependency on `cloudbees-folder` to a runtime dependency, as we now need to reference the `Folder` and any `FolderCredentialsProperty`s. Note that in `JenkinsJobManagementSpec`, we need to use `getNodeTemplate` to ensure that the real implementation of `getXml` is called, which will execute the `configuredBlocks`. Because we need to call to the `configure` method, we need to call out to a new Groovy file, `DslItemConfigurer`, which processes the new `AbstractFolderProperty` and converts it to the correct XML representation. When parsing it, we need to make sure we add a valid XML header, otherwise `XmlParser` will reject it. Closes JENKINS-44681.
- Loading branch information
1 parent
b3bd348
commit 8d8ea63
Showing
5 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
job-dsl-plugin/src/main/groovy/javaposse/jobdsl/plugin/DslItemConfigurer.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package javaposse.jobdsl.plugin | ||
|
||
import com.cloudbees.hudson.plugins.folder.AbstractFolderProperty | ||
import hudson.model.Items | ||
import javaposse.jobdsl.dsl.Item | ||
|
||
class DslItemConfigurer { | ||
private static final String XML_HEADER = "<?xml version='1.1' encoding='UTF-8'?>" | ||
|
||
/** | ||
* Merge an {@link AbstractFolderProperty} into a new {@link Item}'s properties. | ||
* | ||
* @param item the property to merge | ||
* @param dslItem the DSL item to merge the properties into | ||
*/ | ||
static void mergeCredentials(AbstractFolderProperty<?> property, Item dslItem) { | ||
String xml = Items.XSTREAM2.toXML(property) | ||
Node node = new XmlParser().parseText(XML_HEADER + xml) | ||
dslItem.configure { p -> p / 'properties' << node } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<com.cloudbees.hudson.plugins.folder.Folder> | ||
</com.cloudbees.hudson.plugins.folder.Folder> |