Create a folder credential of type "secret file" and "secret text" with Job DSL

Hello,
I am looking for a way to define a folder credential of type “secret file” and “secret text” with Job DSL.
Up to now i was able to generate a folder with a username/password credential using the following snippet:

folder("test") {
    description 'The folder contains all jobs for regular tests'
    properties {
        folderCredentialsProperty {
            domainCredentials {
                domainCredentials {
                    domain {
                        name("test")
                        description("Credentials necessary for our tests")
                    }
                    credentials {
                        usernamePasswordCredentialsImpl {
                            scope("GLOBAL")
                            id("test_user_id")
                            description("User for deployments on test environment")
                            username("test_user_dev")
                            password("password")
                        }
                    }
                }
            }
        }
    }
}

Does anyone can provide me a sample in how to create a folder credential for both types “secret text” and “secret file”?

Thanks in advance,
Rainer

To answer my own question: It is not possible to define secret text/file as folder credential in Job DSL because of https://issues.jenkins.io/browse/JENKINS-59971

But I found a solution for secret text:

folder("test-folder2") {
    description 'The folder contains all jobs for regular tests'
    properties {
        folderCredentialsProperty {
            domainCredentials {
                domainCredentials {
                    domain {
                        name("test2")
                        description("Credentials necessary for our tests")
                    }
                    credentials {
						
                        stringCredentialsImpl {
                            scope("GLOBAL")
                            id("test_user_secret_text")
							description("")
							secret(hudson.util.Secret.fromString('mysecret'))
                        }
                    }
                }
            }
        }
    }
}

Hello,

The code works correctly, but every time I execute it, the domain is erased and then recreated. The issue arises when I need to use an existing domain with preconfigured credentials, then these credentials are deleted by the code. Is there a solution to preserve existing credentials when specifying an existing domain?

Thanks in advance