How to access credential binding variables within configure block?

93 views
Skip to first unread message

Christian Myrhøj

unread,
Nov 25, 2015, 9:48:04 AM11/25/15
to job-dsl-plugin


Hi

I'm trying to setup a Job DSL job to spawn some jobs where the SCM is TFS.
I then want to bind the credentials named "ID" to two variables and inject them into a configure block when spawning the jobs.

When I try to access the variables defined when using "credentialsBinding " and "usernamePassword('TFS_USER', 'TFS_PASS', 'ID')", the jobs won't spawn at all.
How do I access the credentials binding and then inject them into the configure block seen in the code below?

def projects = ['a', 'b', 'c', 'd', 'e', 'f']
 

for(name in projects) {
  def projName = name
  
  freeStyleJob(projName) {
    
    wrappers {
        credentialsBinding {
            usernamePassword('TFS_USER', 'TFS_PASS', 'ID')
            }
  }
        
    configure { project ->
      project.remove(project / scm)
      project / scm(class: 'hudson.plugins.tfs.TeamFoundationServerScm') {
        serverUrl 'http://some_TFS_server:8080/tfs/Datacollection'
        projectPath '$/' + projName
        workspaceName 'Hudson-' + projName + '-' + NODE_NAME
        useUpdate true
        
        password ${TFS_PASS}
        userName ${TFS_USER}
      }
    }
  }
}

Kind regards
Christian Myrhøj 

Daniel Spilker

unread,
Nov 25, 2015, 2:08:27 PM11/25/15
to job-dsl...@googlegroups.com
You must not confuse variables in the DSL script which are evaluated when the script is executed with job variables which are populated and evaluate then running the generated job.

The credentials binding plugin injects variables in your generated job when running that job. The variables in your configure block are evaluated when executing the DSL script in the seed job.

You could add the credentials bindings configuration to your seed job. Then the variables are available in the DSL scripts.

Daniel

--
You received this message because you are subscribed to the Google Groups "job-dsl-plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugi...@googlegroups.com.
To post to this group, send email to job-dsl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/d975ccd9-d84c-4efb-8bf2-f49ddb7080be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages