forked from jenkinsci/parameterized-trigger-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix check webmethod for BuildTriggerConfig projectList and clean up J…
…elly that used old idioms Repairs defect found in demo that for workflow jobs, UI shows "project is not buildable" error in UI Also, remove some trailing whitespace
- Loading branch information
Showing
2 changed files
with
30 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,15 +25,19 @@ | |
import hudson.model.ParametersAction; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import hudson.model.queue.Tasks; | ||
import hudson.plugins.parameterizedtrigger.AbstractBuildParameters.DontTriggerException; | ||
import hudson.plugins.promoted_builds.Promotion; | ||
import hudson.security.ACL; | ||
import hudson.tasks.Messages; | ||
import hudson.Util; | ||
import hudson.util.FormValidation; | ||
import hudson.util.VersionNumber; | ||
|
||
import jenkins.model.Jenkins; | ||
import jenkins.model.ParameterizedJobMixIn; | ||
import jenkins.security.QueueItemAuthenticatorConfiguration; | ||
import org.acegisecurity.Authentication; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.kohsuke.stapler.AncestorInPath; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
@@ -421,10 +425,10 @@ private List<List<AbstractBuildParameters>> getDynamicBuildParameters(AbstractBu | |
|
||
/** | ||
* Create UpstreamCause that triggers a downstream build. | ||
* | ||
* | ||
* If the upstream build is a promotion, return the UpstreamCause | ||
* as triggered by the target of the promotion. | ||
* | ||
* | ||
* @param build an upstream build | ||
* @return UpstreamCause | ||
*/ | ||
|
@@ -433,10 +437,10 @@ protected Cause createUpstreamCause(Run<?, ?> build) { | |
// Test only when promoted-builds is installed. | ||
if(build instanceof Promotion) { | ||
Promotion promotion = (Promotion)build; | ||
|
||
// This cannot be done for PromotionCause#PromotionCause is in a package scope. | ||
// return new PromotionCause(build, promotion.getTarget()); | ||
|
||
return new UpstreamCause((Run<?,?>)promotion.getTarget()); | ||
} | ||
} | ||
|
@@ -479,11 +483,11 @@ protected Future schedule(AbstractBuild<?, ?> build, Job project, List<Action> l | |
|
||
/** | ||
* A backport of {@link Items#computeRelativeNamesAfterRenaming(String, String, String, ItemGroup)} in Jenkins 1.530. | ||
* | ||
* | ||
* computeRelativeNamesAfterRenaming contains a bug in Jenkins < 1.530. | ||
* Replace this to {@link Items#computeRelativeNamesAfterRenaming(String, String, String, ItemGroup)} | ||
* when updated the target version to >= 1.530. | ||
* | ||
* | ||
* @param oldFullName | ||
* @param newFullName | ||
* @param relativeNames | ||
|
@@ -593,7 +597,7 @@ public List<Descriptor<AbstractBuildParameterFactory>> getBuilderConfigFactoryDe | |
* | ||
* Copied from hudson.tasks.BuildTrigger.doCheck(Item project, String value) | ||
*/ | ||
public FormValidation doCheckProjects(@AncestorInPath AbstractProject<?,?> project, @QueryParameter String value ) { | ||
public FormValidation doCheckProjects(@AncestorInPath Job<?,?> project, @QueryParameter String value ) { | ||
// Require CONFIGURE permission on this project | ||
if(!project.hasPermission(Item.CONFIGURE)){ | ||
return FormValidation.ok(); | ||
|
@@ -605,17 +609,29 @@ public FormValidation doCheckProjects(@AncestorInPath AbstractProject<?,?> proje | |
if (StringUtils.isNotBlank(projectName)) { | ||
Item item = Jenkins.getInstance().getItem(projectName,project,Item.class); // only works after version 1.410 | ||
if(item==null){ | ||
return FormValidation.error(Messages.BuildTrigger_NoSuchProject(projectName,AbstractProject.findNearest(projectName).getName())); | ||
Item nearest = Items.findNearest(Job.class, projectName, Jenkins.getInstance()); | ||
String alternative = nearest != null ? nearest.getRelativeNameFrom(project) : "?"; | ||
return FormValidation.error(Messages.BuildTrigger_NoSuchProject(projectName, alternative)); | ||
} | ||
if(!(item instanceof AbstractProject)){ | ||
if(!(item instanceof Job)){ | ||
return FormValidation.error(Messages.BuildTrigger_NotBuildable(projectName)); | ||
} | ||
|
||
// check whether the supposed user is expected to be able to build | ||
if (project instanceof ParameterizedJobMixIn.ParameterizedJob) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
Authentication auth = Tasks.getAuthenticationOf((ParameterizedJobMixIn.ParameterizedJob)project); | ||
if (auth.equals(ACL.SYSTEM) && !QueueItemAuthenticatorConfiguration.get().getAuthenticators().isEmpty()) { | ||
auth = Jenkins.ANONYMOUS; // compare behavior in execute, above | ||
This comment has been minimized.
Sorry, something went wrong.
jglick
|
||
} | ||
if (!item.getACL().hasPermission(auth, Item.BUILD)) { | ||
return FormValidation.error(Messages.BuildTrigger_you_have_no_permission_to_build_(projectName)); | ||
} | ||
} | ||
hasProjects = true; | ||
} | ||
} | ||
if (!hasProjects) { | ||
// return FormValidation.error(Messages.BuildTrigger_NoProjectSpecified()); // only works with Jenkins version built after 2011-01-30 | ||
return FormValidation.error("No project specified"); | ||
return FormValidation.error(Messages.BuildTrigger_NoProjectSpecified()); | ||
} | ||
|
||
return FormValidation.ok(); | ||
|
9 changes: 3 additions & 6 deletions
9
src/main/resources/hudson/plugins/parameterizedtrigger/BuildTriggerConfig/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
🐜 if
!(project instanceof ParameterizedJobMixIn.ParameterizedJob)
then you will not be able to trigger that job so this should be treated as an error (BuildTrigger.NotBuildable
as above).