How to append new credentialsBinding to wrappers node

130 views
Skip to first unread message

Toni Van de Voorde

unread,
Feb 21, 2018, 7:15:14 AM2/21/18
to job-dsl-plugin
Hi everyone,

I'm in a situation where I need to append some new credentials to the "credentialsBinding" node.

I'm trying to do the following:

Imagine that some job is created:

def job = freeStyleJob("some_job") {
  wrappers
{
    credentialsBinding
{
       usernamePassword
('AWS_ECS_USER', 'AWS_ECS_PASSWORD', 'aws-ecs')
   
}
 
}
}

Later on, in a utility class, I add some additional behaviours where I need other credentials. Currently I do this:

job.with {
  wrappers
{
    credentialsBinding
{
      usernamePassword
('BITBUCKET_API_USER', 'BITBUCKET_API_PASSWORD', 'bitbucket-api')
   
}
}

The problem is that the latter will be used because it does not generate well the config.xml

It generates following xml

<buildWrappers>
 
<org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper>
   
<bindings>
     
<org.jenkinsci.plugins.credentialsbinding.impl.UsernamePasswordMultiBinding>
       
<credentialsId>aws-ecs</credentialsId>
       
<usernameVariable>AWS_ECS_USER</usernameVariable>
       
<passwordVariable>AWS_ECS_PASSWORD</passwordVariable>
     
</org.jenkinsci.plugins.credentialsbinding.impl.UsernamePasswordMultiBinding>
   
</bindings>
 
</org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper>
 
<org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper>
   
<bindings>
     
<org.jenkinsci.plugins.credentialsbinding.impl.UsernamePasswordMultiBinding>
       
<credentialsId>bitbucket-api</credentialsId>
       
<usernameVariable>BITBUCKET_API_USER</usernameVariable>
       
<passwordVariable>BITBUCKET_API_PASSWORD</passwordVariable>
     
</org.jenkinsci.plugins.credentialsbinding.impl.UsernamePasswordMultiBinding>
   
</bindings>
 
</org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper>
</buildWrappers>

while it should be

<buildWrappers>
 
<org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper plugin="credentia...@1.15">
   
<bindings>
     
<org.jenkinsci.plugins.credentialsbinding.impl.UsernamePasswordMultiBinding>
       
<credentialsId>bitbucket-api</credentialsId>
       
<usernameVariable>BITBUCKET_API_USER</usernameVariable>
       
<passwordVariable>BITBUCKET_API_PASSWORD</passwordVariable>
     
</org.jenkinsci.plugins.credentialsbinding.impl.UsernamePasswordMultiBinding>
     
<org.jenkinsci.plugins.credentialsbinding.impl.UsernamePasswordMultiBinding>
       
<credentialsId>aws-ecs</credentialsId>
       
<usernameVariable>AWS_ECS_USER</usernameVariable>
       
<passwordVariable>AWS_ECS_PASSWORD</passwordVariable>
     
</org.jenkinsci.plugins.credentialsbinding.impl.UsernamePasswordMultiBinding>
   
</bindings>
 
</org.jenkinsci.plugins.credentialsbinding.impl.SecretBuildWrapper>¨
</buildWrappers>

Is the only solution to use "The Configure Block" method? 

Cheers

Toni
Reply all
Reply to author
Forward
0 new messages