Skip to content

Commit 92cecf8

Browse files
committed
Merge branch 'JENKINS-36370'
2 parents 949cf75 + 5b2f224 commit 92cecf8

4 files changed

Lines changed: 63 additions & 5 deletions

File tree

docs/Home.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins
2727

2828
## Release Notes
2929
* 1.49 (unreleased)
30+
* Enhanced support for the [Sauce OnDemand Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Sauce+OnDemand+Plugin)
31+
([JENKINS-36370](https://issues.jenkins-ci.org/browse/JENKINS-36370))
3032
* 1.48 (June 24 2016)
3133
* Added option to ignore missing DSL script files or empty wildcards
3234
([JENKINS-34060](https://issues.jenkins-ci.org/browse/JENKINS-34060))

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package javaposse.jobdsl.dsl.helpers.wrapper
22

3-
import javaposse.jobdsl.dsl.Context
3+
import javaposse.jobdsl.dsl.AbstractContext
4+
import javaposse.jobdsl.dsl.JobManagement
5+
import javaposse.jobdsl.dsl.RequiresPlugin
46

5-
class SauceOnDemandContext implements Context {
7+
class SauceOnDemandContext extends AbstractContext {
68
boolean useGeneratedTunnelIdentifier
79
boolean sendUsageData
810
boolean enableSauceConnect
@@ -14,9 +16,14 @@ class SauceOnDemandContext implements Context {
1416
String seleniumHost
1517
String seleniumPort
1618
String options
19+
String credentialsId
1720
List<String> webDriverBrowsers = []
1821
List<String> appiumBrowsers = []
1922

23+
SauceOnDemandContext(JobManagement jobManagement) {
24+
super(jobManagement)
25+
}
26+
2027
/**
2128
* Specifies the browsers to test with Appium. Can be called multiple times to add more browsers.
2229
*/
@@ -31,6 +38,16 @@ class SauceOnDemandContext implements Context {
3138
this.webDriverBrowsers.addAll(webDriverBrowsers)
3239
}
3340

41+
/**
42+
* Sets the credentials a build should use.
43+
*
44+
* @since 1.49
45+
*/
46+
@RequiresPlugin(id = 'sauce-ondemand', minimumVersion = '1.148')
47+
void credentials(String credentialsId) {
48+
this.credentialsId = credentialsId
49+
}
50+
3451
/**
3552
* Sets the command line options to be included when launching Sauce Connect.
3653
*/

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ class WrapperContext extends AbstractExtensibleContext {
614614
*/
615615
@RequiresPlugin(id = 'sauce-ondemand', minimumVersion = '1.142')
616616
void sauceOnDemand(@DslContext(SauceOnDemandContext) Closure closure) {
617-
SauceOnDemandContext context = new SauceOnDemandContext()
617+
SauceOnDemandContext context = new SauceOnDemandContext(jobManagement)
618618
ContextHelper.executeInContext(closure, context)
619619

620620
wrapperNodes << new NodeBuilder().'hudson.plugins.sauce__ondemand.SauceOnDemandBuildWrapper' {
@@ -639,6 +639,9 @@ class WrapperContext extends AbstractExtensibleContext {
639639
useLatestVersion(context.useLatestVersion)
640640
launchSauceConnectOnSlave(context.launchSauceConnectOnSlave)
641641
options(context.options ?: '')
642+
if (jobManagement.isMinimumPluginVersionInstalled('sauce-ondemand', '1.148')) {
643+
credentialId(context.credentialsId ?: '')
644+
}
642645
verboseLogging(context.verboseLogging)
643646
condition(class: 'org.jenkins_ci.plugins.run_condition.core.AlwaysRun')
644647
}

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ class WrapperContextSpec extends Specification {
11041104
1 * mockJobManagement.requirePlugin('nodejs')
11051105
}
11061106

1107-
def 'call sauce on demand with defaults'() {
1107+
def 'call sauce on demand with defaults for older plugin version'() {
11081108
when:
11091109
context.sauceOnDemand {
11101110
}
@@ -1131,7 +1131,41 @@ class WrapperContextSpec extends Specification {
11311131
}
11321132
}
11331133

1134+
def 'call sauce on demand with defaults'() {
1135+
given:
1136+
mockJobManagement.isMinimumPluginVersionInstalled('sauce-ondemand', '1.148') >> true
1137+
1138+
when:
1139+
context.sauceOnDemand {
1140+
}
1141+
1142+
then:
1143+
with(context.wrapperNodes[0]) {
1144+
name() == 'hudson.plugins.sauce__ondemand.SauceOnDemandBuildWrapper'
1145+
children().size() == 16
1146+
useGeneratedTunnelIdentifier[0].value() == false
1147+
sendUsageData[0].value() == false
1148+
nativeAppPackage[0].value() == ''
1149+
useChromeForAndroid[0].value() == false
1150+
sauceConnectPath[0].value() == ''
1151+
enableSauceConnect[0].value() == false
1152+
seleniumHost[0].value() == ''
1153+
seleniumPort[0].value() == ''
1154+
webDriverBrowsers[0].value().empty
1155+
appiumBrowsers[0].value().empty
1156+
useLatestVersion[0].value() == false
1157+
launchSauceConnectOnSlave[0].value() == false
1158+
options[0].value() == ''
1159+
credentialId[0].value() == ''
1160+
verboseLogging[0].value() == false
1161+
condition[0].attribute('class') == 'org.jenkins_ci.plugins.run_condition.core.AlwaysRun'
1162+
}
1163+
}
1164+
11341165
def 'call sauce on demand with all options'() {
1166+
given:
1167+
mockJobManagement.isMinimumPluginVersionInstalled('sauce-ondemand', '1.148') >> true
1168+
11351169
when:
11361170
context.sauceOnDemand {
11371171
useGeneratedTunnelIdentifier()
@@ -1148,13 +1182,14 @@ class WrapperContextSpec extends Specification {
11481182
useLatestVersion()
11491183
launchSauceConnectOnSlave()
11501184
options('options')
1185+
credentials('credentialId')
11511186
verboseLogging()
11521187
}
11531188

11541189
then:
11551190
with(context.wrapperNodes[0]) {
11561191
name() == 'hudson.plugins.sauce__ondemand.SauceOnDemandBuildWrapper'
1157-
children().size() == 15
1192+
children().size() == 16
11581193
useGeneratedTunnelIdentifier[0].value() == true
11591194
sendUsageData[0].value() == true
11601195
nativeAppPackage[0].value() == 'nativeAppPackage'
@@ -1174,6 +1209,7 @@ class WrapperContextSpec extends Specification {
11741209
useLatestVersion[0].value() == true
11751210
launchSauceConnectOnSlave[0].value() == true
11761211
options[0].value() == 'options'
1212+
credentialId[0].value() == 'credentialId'
11771213
verboseLogging[0].value() == true
11781214
condition[0].attribute('class') == 'org.jenkins_ci.plugins.run_condition.core.AlwaysRun'
11791215
}

0 commit comments

Comments
 (0)