Github credentials

134 views
Skip to first unread message

Adrian Staś

unread,
Oct 21, 2014, 9:12:48 AM10/21/14
to job-dsl...@googlegroups.com
Hi everyone

I'd like to get all branches from my github repository, but I can't find any information how could I use jenkins stored credentials or any plain input method. 

Could somebody tell how the following script should be extended?

def project = 'quidryan/aws-sdk-test'
def branchApi = new URL("https://api.github.com/repos/${project}/branches")
def branches = new groovy.json.JsonSlurper().parse(branchApi.newReader())
branches
.each {
   
def branchName = it.name
    job
{
        name
"${project}-${branchName}".replaceAll('/','-')
        scm
{
            git
("git://github.com/${project}.git", branchName)
        }
        steps
{
            maven
("test -Dproject.name=${project}/${branchName}")
       
}
   
}
}

thanks a lot,
Adrian

martino turturiello

unread,
Jan 20, 2016, 5:27:34 PM1/20/16
to job-dsl-plugin
I am facing the same issue, any help on this?

Thanks!

Fiouz

unread,
Jan 21, 2016, 10:45:02 PM1/21/16
to job-dsl-plugin

Assuming you defined a credentials domain with a 'github.com' hostname specification and want any kind of credentials (username/password, username/private SSH key, etc.) :

Class type = com.cloudbees.plugins.credentials.Credentials.class; // change as needed

 

def id = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(

  type,

  jenkins.model.Jenkins.activeInstance,

  hudson.security.ACL.SYSTEM,

  new com.cloudbees.plugins.credentials.domains.HostnameRequirement('github.com')

).find {

  true // extra condition here

}?.id;

And use the resulting id in your git remote credentials.


--
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/1cd27e6c-3f25-404e-a3f0-bc4fbfb9096c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

--
Fiouz

Daniel Spilker

unread,
Jan 27, 2016, 3:44:24 PM1/27/16
to job-dsl...@googlegroups.com
I'm going to remove the dependency to the Credentials plugin in 1.43 because it's no longer used in the Job DSL plugin. Due to that change, it will no longer be possible to use classes from the Credentials plugin in DSL scripts.

As an alternative, I suggest to use the Credentials Binding plugin [1] to bind the credentials to some environment variables and then use [2] these variables in the DSL script.

Daniel
Reply all
Reply to author
Forward
0 new messages