Skip to content

Commit dc862e3

Browse files
committed
added support for multiple credentials for SSH Agent plugin
1 parent f34ec00 commit dc862e3

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

docs/Home.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins
3232
([JENKINS-40797](https://issues.jenkins-ci.org/browse/JENKINS-40797))
3333
* Enhanced support for the [Extra Columns Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Extra+Columns+Plugin)
3434
([#978](https://github.com/jenkinsci/job-dsl-plugin/pull/978))
35+
* Enhanced support for the [SSH Agent Plugin](https://wiki.jenkins-ci.org/display/JENKINS/SSH+Agent+Plugin)
36+
([#980](https://github.com/jenkinsci/job-dsl-plugin/pull/980))
3537
* 1.55 (January 03 2016)
3638
* Updated optional
3739
[Config File Provider Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Config+File+Provider+Plugin) dependency to

job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/wrapper/WrapperContext.groovy

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,25 @@ class WrapperContext extends AbstractExtensibleContext {
193193
}
194194
}
195195

196+
/**
197+
* Provide SSH credentials to builds via a ssh-agent in Jenkins.
198+
*
199+
* @param credentials name of the credentials to use
200+
* @since 1.56
201+
*/
202+
@RequiresPlugin(id = 'ssh-agent', minimumVersion = '1.5')
203+
void sshAgent(String... credentials) {
204+
Preconditions.checkNotNull(credentials, 'credentials must not be null')
205+
206+
wrapperNodes << new NodeBuilder().'com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper' {
207+
credentialIds {
208+
credentials.each {
209+
string(it)
210+
}
211+
}
212+
}
213+
}
214+
196215
/**
197216
* Renders ANSI escape sequences, including color, to console output.
198217
*

job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/wrapper/WrapperContextSpec.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,19 @@ class WrapperContextSpec extends Specification {
401401
1 * mockJobManagement.requirePlugin('ssh-agent')
402402
}
403403

404+
def 'sshAgent with multiple credentials'() {
405+
when:
406+
context.sshAgent('acme', 'foo')
407+
408+
then:
409+
context.wrapperNodes[0].name() == 'com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper'
410+
context.wrapperNodes[0].children().size() == 1
411+
context.wrapperNodes[0].credentialIds[0].children().size() == 2
412+
context.wrapperNodes[0].credentialIds[0].string[0].value() == 'acme'
413+
context.wrapperNodes[0].credentialIds[0].string[1].value() == 'foo'
414+
1 * mockJobManagement.requireMinimumPluginVersion('ssh-agent', '1.5')
415+
}
416+
404417
def 'ansiColor with map'() {
405418
when:
406419
context.colorizeOutput('foo')

0 commit comments

Comments
 (0)