6
6
import com .saucelabs .ci .sauceconnect .AbstractSauceTunnelManager ;
7
7
import com .saucelabs .ci .sauceconnect .SauceConnectManager ;
8
8
import com .saucelabs .jenkins .HudsonSauceManagerFactory ;
9
+ import com .saucelabs .saucerest .DataCenter ;
9
10
import edu .umd .cs .findbugs .annotations .NonNull ;
10
11
import hudson .Extension ;
11
12
import hudson .ProxyConfiguration ;
@@ -48,25 +49,28 @@ public class SauceConnectStep extends Step {
48
49
private Boolean useLatestSauceConnect = false ;
49
50
private Boolean useGeneratedTunnelIdentifier = false ;
50
51
private String options ;
52
+ private String optionsSC5 ;
51
53
private String sauceConnectPath ;
52
54
53
55
@ DataBoundConstructor
54
56
public SauceConnectStep () {
55
57
}
56
58
57
- public SauceConnectStep (String options , Boolean verboseLogging , Boolean useLatestSauceConnect , Boolean useGeneratedTunnelIdentifier , String sauceConnectPath ) {
59
+ public SauceConnectStep (String options , String optionsSC5 , Boolean verboseLogging , Boolean useLatestSauceConnect , Boolean useGeneratedTunnelIdentifier , String sauceConnectPath ) {
58
60
this .verboseLogging = verboseLogging ;
59
61
this .useLatestSauceConnect = useLatestSauceConnect ;
60
62
this .useGeneratedTunnelIdentifier = useGeneratedTunnelIdentifier ;
61
63
this .sauceConnectPath = Util .fixEmptyAndTrim (sauceConnectPath );
62
64
this .options = StringUtils .trimToEmpty (options );
65
+ this .optionsSC5 = StringUtils .trimToEmpty (optionsSC5 );
63
66
}
64
67
65
68
@ Override
66
69
public StepExecution start (StepContext context ) throws Exception {
67
70
return new SauceConnectStepExecution (context ,
68
71
PluginImpl .get ().getSauceConnectOptions (),
69
72
options ,
73
+ optionsSC5 ,
70
74
useGeneratedTunnelIdentifier ,
71
75
verboseLogging ,
72
76
sauceConnectPath ,
@@ -82,7 +86,16 @@ public String getOptions() {
82
86
83
87
@ DataBoundSetter
84
88
public void setOptions (String options ) {
85
- this .options = options ;
89
+ this .options = options .strip ();
90
+ }
91
+
92
+ public String getOptionsSC5 () {
93
+ return optionsSC5 ;
94
+ }
95
+
96
+ @ DataBoundSetter
97
+ public void setOptionsSC5 (String optionsSC5 ) {
98
+ this .optionsSC5 = optionsSC5 .strip ();
86
99
}
87
100
88
101
public String getSauceConnectPath () {
@@ -154,16 +167,18 @@ private static final class SauceStartConnectHandler extends MasterToSlaveCallabl
154
167
private final Boolean verboseLogging ;
155
168
private final String sauceConnectPath ;
156
169
private final Boolean useLatestSauceConnect ;
170
+ private final Boolean legacyCLI ;
157
171
private final ProxyConfiguration proxy ;
158
172
159
- SauceStartConnectHandler (SauceCredentials sauceCredentials , int port , String options , TaskListener listener , Boolean verboseLogging , String sauceConnectPath , Boolean useLatestSauceConnect , ProxyConfiguration proxy ) {
173
+ SauceStartConnectHandler (SauceCredentials sauceCredentials , int port , String options , TaskListener listener , Boolean verboseLogging , String sauceConnectPath , Boolean useLatestSauceConnect , Boolean legacyCLI , ProxyConfiguration proxy ) {
160
174
this .sauceCredentials = sauceCredentials ;
161
175
this .port = port ;
162
- this .options = options ;
176
+ this .options = options . strip () ;
163
177
this .listener = listener ;
164
178
this .verboseLogging = verboseLogging ;
165
179
this .sauceConnectPath = sauceConnectPath ;
166
180
this .useLatestSauceConnect = useLatestSauceConnect ;
181
+ this .legacyCLI = legacyCLI ;
167
182
this .proxy = proxy ;
168
183
}
169
184
@@ -175,13 +190,14 @@ public Void call() throws AbstractSauceTunnelManager.SauceConnectException {
175
190
sauceTunnelManager .openConnection (
176
191
sauceCredentials .getUsername (),
177
192
sauceCredentials .getApiKey ().getPlainText (),
178
- sauceCredentials .getRestEndpointName (),
193
+ DataCenter . fromString ( sauceCredentials .getRestEndpointName () ),
179
194
port ,
180
195
null , /*sauceConnectJar,*/
181
196
options ,
182
197
listener .getLogger (),
183
198
verboseLogging ,
184
- sauceConnectPath
199
+ sauceConnectPath ,
200
+ legacyCLI
185
201
);
186
202
return null ;
187
203
}
@@ -217,6 +233,7 @@ public Void call() throws AbstractSauceTunnelManager.SauceConnectException {
217
233
public static class SauceConnectStepExecution extends StepExecution {
218
234
private final String globalOptions ;
219
235
private final String options ;
236
+ private final String optionsSC5 ;
220
237
private final boolean useGeneratedTunnelIdentifier ;
221
238
private final boolean verboseLogging ;
222
239
private final String sauceConnectPath ;
@@ -231,6 +248,7 @@ public SauceConnectStepExecution(
231
248
@ NonNull StepContext context ,
232
249
String globalOptions ,
233
250
String options ,
251
+ String optionsSC5 ,
234
252
boolean useGeneratedTunnelIdentifier ,
235
253
boolean verboseLogging ,
236
254
String sauceConnectPath ,
@@ -240,6 +258,7 @@ public SauceConnectStepExecution(
240
258
super (context );
241
259
this .globalOptions = globalOptions ;
242
260
this .options = options ;
261
+ this .optionsSC5 = optionsSC5 ;
243
262
this .useGeneratedTunnelIdentifier = useGeneratedTunnelIdentifier ;
244
263
this .verboseLogging = verboseLogging ;
245
264
this .sauceConnectPath = sauceConnectPath ;
@@ -249,6 +268,14 @@ public SauceConnectStepExecution(
249
268
250
269
@ Override
251
270
public boolean start () throws Exception {
271
+ boolean legacyCLI = false ;
272
+ if (options != null && optionsSC5 != null && !options .isEmpty () && !optionsSC5 .isEmpty ()) {
273
+ throw new Exception ("Legacy and SC5 CLI options cannot both be specified" );
274
+ }
275
+
276
+ if (options != null && !options .isEmpty ()) {
277
+ legacyCLI = true ;
278
+ }
252
279
253
280
Run <?, ?> run = getContext ().get (Run .class );
254
281
Job <?,?> job = run .getParent ();
@@ -266,10 +293,14 @@ public boolean start() throws Exception {
266
293
267
294
ArrayList <String > optionsArray = new ArrayList <String >();
268
295
optionsArray .add (globalOptions );
269
- optionsArray .add (options );
296
+ if (legacyCLI ) {
297
+ optionsArray .add (options );
298
+ } else {
299
+ optionsArray .add (optionsSC5 );
300
+ }
270
301
optionsArray .removeAll (Collections .singleton ("" )); // remove the empty strings
271
302
272
- String options = StringUtils .join (optionsArray , " " );
303
+ String combinedOptions = StringUtils .join (optionsArray , " " );
273
304
274
305
HashMap <String ,String > overrides = new HashMap <String ,String >();
275
306
overrides .put (SauceOnDemandBuildWrapper .SELENIUM_PORT , String .valueOf (port ));
@@ -278,26 +309,25 @@ public boolean start() throws Exception {
278
309
if (useGeneratedTunnelIdentifier ) {
279
310
final String tunnelName = SauceEnvironmentUtil .generateTunnelName (job .getName (), run .number );
280
311
overrides .put (SauceOnDemandBuildWrapper .TUNNEL_NAME , tunnelName );
281
- options = options + " --tunnel-name " + tunnelName ;
312
+ combinedOptions = combinedOptions + " --tunnel-name " + tunnelName ;
282
313
}
283
314
284
315
SauceCredentials sauceCredentials = getContext ().get (SauceCredentials .class );
285
- final String restEndpoint = sauceCredentials .getRestEndpoint ();
286
-
287
- overrides .put (SauceOnDemandBuildWrapper .SAUCE_REST_ENDPOINT , restEndpoint );
288
- options = options + " -x " + restEndpoint + "rest/v1" ;
316
+ final String region = sauceCredentials .getRegion ();
317
+ combinedOptions = combinedOptions + " --region " + region ;
289
318
290
319
TaskListener listener = getContext ().get (TaskListener .class );
291
320
listener .getLogger ().println ("Starting sauce connect" );
292
321
293
322
SauceStartConnectHandler handler = new SauceStartConnectHandler (
294
323
sauceCredentials ,
295
324
port ,
296
- options ,
325
+ combinedOptions ,
297
326
listener ,
298
327
verboseLogging ,
299
328
sauceConnectPath ,
300
329
useLatestSauceConnect ,
330
+ legacyCLI ,
301
331
proxy
302
332
);
303
333
computer .getChannel ().call (handler );
@@ -352,4 +382,4 @@ private static final class Callback extends BodyExecutionCallback.TailCall {
352
382
353
383
}
354
384
}
355
- }
385
+ }
0 commit comments