10
10
import com .cloudbees .plugins .credentials .domains .URIRequirementBuilder ;
11
11
import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
12
12
import hudson .Extension ;
13
- import hudson .model .AbstractProject ;
14
13
import hudson .model .Build ;
15
14
import hudson .model .Cause ;
15
+ import hudson .model .CauseAction ;
16
16
import hudson .model .Item ;
17
+ import hudson .model .Job ;
17
18
import hudson .model .ParameterDefinition ;
18
19
import hudson .model .ParameterValue ;
19
20
import hudson .model .ParametersAction ;
37
38
import javax .annotation .Nonnull ;
38
39
import javax .annotation .Nullable ;
39
40
import jenkins .model .Jenkins ;
41
+ import jenkins .model .ParameterizedJobMixIn ;
42
+ import jenkins .model .ParameterizedJobMixIn .ParameterizedJob ;
40
43
import net .sf .json .JSONObject ;
41
44
import org .apache .commons .lang .StringUtils ;
42
45
import org .kohsuke .stapler .AncestorInPath ;
47
50
48
51
/** Created by Nathan McCarthy */
49
52
@ SuppressFBWarnings ({"WMI_WRONG_MAP_ITERATOR" , "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE" })
50
- public class StashBuildTrigger extends Trigger <AbstractProject <?, ?>> {
53
+ public class StashBuildTrigger extends Trigger <Job <?, ?>> {
51
54
private static final Logger logger =
52
55
Logger .getLogger (MethodHandles .lookup ().lookupClass ().getName ());
53
56
private final String projectPath ;
@@ -142,7 +145,7 @@ private StandardUsernamePasswordCredentials getCredentials() {
142
145
CredentialsProvider .lookupCredentials (
143
146
StandardUsernamePasswordCredentials .class ,
144
147
this .job ,
145
- Tasks .getDefaultAuthenticationOf (this . job ),
148
+ Tasks .getDefaultAuthenticationOf (( ParameterizedJob ) job ),
146
149
URIRequirementBuilder .fromUri (stashHost ).build ()),
147
150
CredentialsMatchers .allOf (CredentialsMatchers .withId (credentialsId )));
148
151
}
@@ -196,15 +199,15 @@ public boolean isCancelOutdatedJobsEnabled() {
196
199
}
197
200
198
201
@ Override
199
- public void start (AbstractProject <?, ?> project , boolean newInstance ) {
202
+ public void start (Job <?, ?> job , boolean newInstance ) {
200
203
try {
201
- Objects .requireNonNull (project , "project is null" );
202
- this .stashPullRequestsBuilder = new StashPullRequestsBuilder (project , this );
204
+ Objects .requireNonNull (job , "job is null" );
205
+ this .stashPullRequestsBuilder = new StashPullRequestsBuilder (job , this );
203
206
} catch (NullPointerException e ) {
204
207
logger .log (Level .SEVERE , "Can't start trigger" , e );
205
208
return ;
206
209
}
207
- super .start (project , newInstance );
210
+ super .start (job , newInstance );
208
211
}
209
212
210
213
public StashPullRequestsBuilder getBuilder () {
@@ -226,7 +229,19 @@ public QueueTaskFuture<?> startJob(StashCause cause) {
226
229
abortRunningJobsThatMatch (cause );
227
230
}
228
231
229
- return job .scheduleBuild2 (job .getQuietPeriod (), cause , new ParametersAction (values ));
232
+ // TODO: Use ParameterizedJob#getParameterizedJobMixIn() in Jenkins 2.61+
233
+ ParameterizedJobMixIn <?, ?> scheduledJob =
234
+ new ParameterizedJobMixIn () {
235
+ @ Override
236
+ protected Job <?, ?> asJob () {
237
+ return StashBuildTrigger .this .job ;
238
+ }
239
+ };
240
+
241
+ return scheduledJob .scheduleBuild2 (
242
+ ((ParameterizedJob ) job ).getQuietPeriod (),
243
+ new CauseAction (cause ),
244
+ new ParametersAction (values ));
230
245
}
231
246
232
247
private void cancelPreviousJobsInQueueThatMatch (@ Nonnull StashCause stashCause ) {
@@ -333,7 +348,7 @@ public StashBuildTriggerDescriptor() {
333
348
334
349
@ Override
335
350
public boolean isApplicable (Item item ) {
336
- return item instanceof AbstractProject ;
351
+ return item instanceof Job && item instanceof ParameterizedJob ;
337
352
}
338
353
339
354
@ Override
0 commit comments