Okay, now it is clearer to me what your problem is. I will try to reproduce this locally and check how it behaves.
For some reason I have thought that Job DSL plugin throws an error if section, which should not be repeated is repeated, but that does not seem to be the case here. Namely I would have expected the plugin to raise an error for following execution, since it would have seen the credentialsBinding section twice:
wrappers {
sshAgent(gitCredentialId)
colorizeOutput()
credentialsBinding
{
usernamePassword("REDMINE_USER", "REDMINE_API_KEY", "redmine_api")
}
environmentVariables
{
env("REDMINE_URL", "https://issues.redacted") env("RUST_LOG", "info")
}
if(job.containsKey("elts_credentials")) {
credentialsBinding
{
usernamePassword("ELTS_USER", "ELTS_TOKEN", job["elts_credentials"])
}
}
but now I am not sure if such mechanism is even available.
Note that in this case I would expect the block to be called credentialBindings (plural) instead of credentialBinding (singular). That would mean breakage of API, thus I would recommend adding another block instead of changing the behavior of existing block if that is possible.
Also this sound like a good candidate for first issue. If that is the case I would like to lend a hand and start working on this one.