Skip to content

Commit

Permalink
[FIXED JENKINS-20940] Use rootProject as copying sources. This allows…
Browse files Browse the repository at this point in the history
… correct project name resolving from matrix projects.
  • Loading branch information
ikedam committed Jun 17, 2014
1 parent db1e878 commit 06fa458
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/main/java/hudson/plugins/copyartifact/CopyArtifact.java
Expand Up @@ -103,13 +103,15 @@ public CopyArtifact(String projectName, String parameters, BuildSelector selecto
// check the permissions only if we can
StaplerRequest req = Stapler.getCurrentRequest();
if (req!=null) {
ItemGroup context = req.findAncestorObject(ItemGroup.class);
if (context == null) context = Jenkins.getInstance();

// Prevents both invalid values and access to artifacts of projects which this user cannot see.
// If value is parameterized, it will be checked when build runs.
if (projectName.indexOf('$') < 0 && Jenkins.getInstance().getItem(projectName, context, Job.class) == null)
projectName = ""; // Ignore/clear bad value to avoid ugly 500 page
AbstractProject<?,?> p = req.findAncestorObject(AbstractProject.class);
if (p != null) {
ItemGroup<?> context = p.getParent();

// Prevents both invalid values and access to artifacts of projects which this user cannot see.
// If value is parameterized, it will be checked when build runs.
if (projectName.indexOf('$') < 0 && Jenkins.getInstance().getItem(projectName, context, Job.class) == null)
projectName = ""; // Ignore/clear bad value to avoid ugly 500 page
}
}

this.project = projectName;
Expand Down Expand Up @@ -251,7 +253,7 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
EnvVars env = build.getEnvironment(listener);
env.overrideAll(build.getBuildVariables()); // Add in matrix axes..
expandedProject = env.expand(project);
Job<?, ?> job = Jenkins.getInstance().getItem(expandedProject, build.getProject().getParent(), Job.class);
Job<?, ?> job = Jenkins.getInstance().getItem(expandedProject, build.getProject().getRootProject().getParent(), Job.class);
if (job != null && !expandedProject.equals(project)
// If projectName is parameterized, need to do permission check on source project.
&& !canReadFrom(job, build)) {
Expand Down

0 comments on commit 06fa458

Please sign in to comment.