1010import com .cloudbees .plugins .credentials .domains .URIRequirementBuilder ;
1111import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
1212import hudson .Extension ;
13- import hudson .model .AbstractProject ;
1413import hudson .model .Build ;
1514import hudson .model .Cause ;
15+ import hudson .model .CauseAction ;
1616import hudson .model .Item ;
17+ import hudson .model .Job ;
1718import hudson .model .ParameterDefinition ;
1819import hudson .model .ParameterValue ;
1920import hudson .model .ParametersAction ;
3738import javax .annotation .Nonnull ;
3839import javax .annotation .Nullable ;
3940import jenkins .model .Jenkins ;
41+ import jenkins .model .ParameterizedJobMixIn ;
42+ import jenkins .model .ParameterizedJobMixIn .ParameterizedJob ;
4043import net .sf .json .JSONObject ;
4144import org .apache .commons .lang .StringUtils ;
4245import org .kohsuke .stapler .AncestorInPath ;
4750
4851/** Created by Nathan McCarthy */
4952@ 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 <?, ?>> {
5154 private static final Logger logger =
5255 Logger .getLogger (MethodHandles .lookup ().lookupClass ().getName ());
5356 private final String projectPath ;
@@ -142,7 +145,7 @@ private StandardUsernamePasswordCredentials getCredentials() {
142145 CredentialsProvider .lookupCredentials (
143146 StandardUsernamePasswordCredentials .class ,
144147 this .job ,
145- Tasks .getDefaultAuthenticationOf (this . job ),
148+ Tasks .getDefaultAuthenticationOf (( Queue . Task ) job ),
146149 URIRequirementBuilder .fromUri (stashHost ).build ()),
147150 CredentialsMatchers .allOf (CredentialsMatchers .withId (credentialsId )));
148151 }
@@ -196,15 +199,15 @@ public boolean isCancelOutdatedJobsEnabled() {
196199 }
197200
198201 @ Override
199- public void start (AbstractProject <?, ?> project , boolean newInstance ) {
202+ public void start (Job <?, ?> job , boolean newInstance ) {
200203 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 );
203206 } catch (NullPointerException e ) {
204207 logger .log (Level .SEVERE , "Can't start trigger" , e );
205208 return ;
206209 }
207- super .start (project , newInstance );
210+ super .start (job , newInstance );
208211 }
209212
210213 public StashPullRequestsBuilder getBuilder () {
@@ -226,7 +229,18 @@ public QueueTaskFuture<?> startJob(StashCause cause) {
226229 abortRunningJobsThatMatch (cause );
227230 }
228231
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 ));
230244 }
231245
232246 private void cancelPreviousJobsInQueueThatMatch (@ Nonnull StashCause stashCause ) {
@@ -333,7 +347,7 @@ public StashBuildTriggerDescriptor() {
333347
334348 @ Override
335349 public boolean isApplicable (Item item ) {
336- return true ;
350+ return item instanceof Job && item instanceof ParameterizedJob && item instanceof Queue . Task ;
337351 }
338352
339353 @ Override
0 commit comments