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 (( Queue . Task ) 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,18 @@ public QueueTaskFuture<?> startJob(StashCause cause) {
226
229
abortRunningJobsThatMatch (cause );
227
230
}
228
231
229
- return job .scheduleBuild2 (job .getQuietPeriod (), cause , new ParametersAction (values ));
232
+ ParameterizedJobMixIn jobMixIn =
233
+ new ParameterizedJobMixIn () {
234
+ @ Override
235
+ protected Job asJob () {
236
+ return StashBuildTrigger .this .job ;
237
+ }
238
+ };
239
+
240
+ return jobMixIn .scheduleBuild2 (
241
+ ((ParameterizedJob ) job ).getQuietPeriod (),
242
+ new CauseAction (cause ),
243
+ new ParametersAction (values ));
230
244
}
231
245
232
246
private void cancelPreviousJobsInQueueThatMatch (@ Nonnull StashCause stashCause ) {
@@ -333,7 +347,7 @@ public StashBuildTriggerDescriptor() {
333
347
334
348
@ Override
335
349
public boolean isApplicable (Item item ) {
336
- return true ;
350
+ return item instanceof Job && item instanceof ParameterizedJob && item instanceof Queue . Task ;
337
351
}
338
352
339
353
@ Override
0 commit comments