Skip to content

Commit 439308d

Browse files
authored
Merge pull request #980 from daspilker/ssh-agent
Allow multiple credentials for SSH Agent
2 parents f34ec00 + 584b2a4 commit 439308d

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

docs/Home.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ 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))
37+
* Support for the older versions of the
38+
[SSH Agent Plugin](https://wiki.jenkins-ci.org/display/JENKINS/SSH+Agent+Plugin),
39+
see [Migration](Migration#migrating-to-156)
3540
* 1.55 (January 03 2016)
3641
* Updated optional
3742
[Config File Provider Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Config+File+Provider+Plugin) dependency to

docs/Migration.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## Migrating to 1.56
2+
3+
### SSH Agent
4+
5+
Support for versions older than 1.5 of the
6+
[SSH Agent Plugin](https://wiki.jenkins-ci.org/display/JENKINS/SSH+Agent+Plugin) is [[deprecated|Deprecation-Policy]]
7+
and will be removed.
8+
19
## Migrating to 1.55
210

311
### ScriptRequest

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,33 @@ class WrapperContext extends AbstractExtensibleContext {
186186
*/
187187
@RequiresPlugin(id = 'ssh-agent')
188188
void sshAgent(String credentials) {
189+
jobManagement.logPluginDeprecationWarning('ssh-agent', '1.5')
189190
Preconditions.checkNotNull(credentials, 'credentials must not be null')
190191

191192
wrapperNodes << new NodeBuilder().'com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper' {
192193
user(credentials)
193194
}
194195
}
195196

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

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,20 @@ class WrapperContextSpec extends Specification {
399399
context.wrapperNodes[0].name() == 'com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper'
400400
context.wrapperNodes[0].user[0].value() == 'acme'
401401
1 * mockJobManagement.requirePlugin('ssh-agent')
402+
1 * mockJobManagement.logPluginDeprecationWarning('ssh-agent', '1.5')
403+
}
404+
405+
def 'sshAgent with multiple credentials'() {
406+
when:
407+
context.sshAgent('acme', 'foo')
408+
409+
then:
410+
context.wrapperNodes[0].name() == 'com.cloudbees.jenkins.plugins.sshagent.SSHAgentBuildWrapper'
411+
context.wrapperNodes[0].children().size() == 1
412+
context.wrapperNodes[0].credentialIds[0].children().size() == 2
413+
context.wrapperNodes[0].credentialIds[0].string[0].value() == 'acme'
414+
context.wrapperNodes[0].credentialIds[0].string[1].value() == 'foo'
415+
1 * mockJobManagement.requireMinimumPluginVersion('ssh-agent', '1.5')
402416
}
403417

404418
def 'ansiColor with map'() {

0 commit comments

Comments
 (0)