|
@@ -50,13 +50,15 @@ |
|
|
import hudson.util.VersionNumber; |
|
|
|
|
|
import java.io.IOException; |
|
|
import java.nio.charset.Charset; |
|
|
import java.util.Collections; |
|
|
import java.util.HashMap; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Set; |
|
|
import java.util.concurrent.Callable; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
import java.util.logging.Logger; |
|
|
|
|
|
import jenkins.model.Jenkins; |
|
|
|
|
@@ -1400,6 +1402,152 @@ public void testWebConfiguration() throws Exception { |
|
|
} |
|
|
} |
|
|
|
|
|
private boolean isFilePermissionSupported() throws Exception { |
|
|
return jenkins.getRootPath().mode() != -1; |
|
|
} |
|
|
|
|
|
public void testFilePermission() throws Exception { |
|
|
if (!isFilePermissionSupported()) { |
|
|
Logger.getLogger(CopyArtifactTest.class.getName()).warning(String.format( |
|
|
"Skipped %s as file permission is not supported on this platform", |
|
|
getName() |
|
|
)); |
|
|
return; |
|
|
} |
|
|
|
|
|
FreeStyleProject copiee = createFreeStyleProject(); |
|
|
FreeStyleBuild copieeBuild = copiee.scheduleBuild2(0).get(); |
|
|
assertBuildStatusSuccess(copieeBuild); |
|
|
|
|
|
// As I cannot trust ArtifactArchiver (JENKINS-14269), |
|
|
// creates artifacts manually. |
|
|
FilePath artifactDir = new FilePath(copieeBuild.getArtifactsDir()); |
|
|
artifactDir.child("artifact.txt").write("some content", Charset.defaultCharset().name()); |
|
|
artifactDir.child("artifact.txt").chmod(644); |
|
|
artifactDir.child("artifactWithExecute.txt").write("some content", Charset.defaultCharset().name()); |
|
|
artifactDir.child("artifactWithExecute.txt").chmod(644); |
|
|
artifactDir.child("subdir").mkdirs(); |
|
|
artifactDir.child("subdir/artifactInSubdir.txt").write("some content", Charset.defaultCharset().name()); |
|
|
artifactDir.child("subdir/artifactInSubdir.txt").chmod(644); |
|
|
artifactDir.child("subdir/artifactInSubdir.txt").write("some content", Charset.defaultCharset().name()); |
|
|
artifactDir.child("subdir/artifactInSubdir.txt").chmod(644); |
|
|
|
|
|
assertEquals(0644, artifactDir.child("artifact.txt").mode()); |
|
|
assertEquals(0755, artifactDir.child("artifactWithExecute.txt").mode()); |
|
|
assertEquals(0644, artifactDir.child("subdir/artifactInSubdir.txt").mode()); |
|
|
assertEquals(0755, artifactDir.child("subdir/artifactWithExecuteInSubdir.txt").mode()); |
|
|
|
|
|
// on master, without flatten |
|
|
{ |
|
|
FreeStyleProject p = createFreeStyleProject(); |
|
|
p.setAssignedNode(jenkins); |
|
|
p.getBuildersList().add(new CopyArtifact( |
|
|
copiee.getFullName(), |
|
|
"", |
|
|
new SpecificBuildSelector(Integer.toString(copieeBuild.getNumber())), |
|
|
"", |
|
|
"", |
|
|
"", |
|
|
false, |
|
|
false, |
|
|
false |
|
|
)); |
|
|
FreeStyleBuild b = p.scheduleBuild2(0).get(); |
|
|
assertBuildStatusSuccess(b); |
|
|
|
|
|
assertEquals(jenkins, b.getBuiltOn()); |
|
|
|
|
|
FilePath w = b.getWorkspace(); |
|
|
assertEquals(0644, w.child("artifact.txt").mode()); |
|
|
assertEquals(0755, w.child("artifactWithExecute.txt").mode()); |
|
|
assertEquals(0644, w.child("subdir/artifactInSubdir.txt").mode()); |
|
|
assertEquals(0755, w.child("subdir/artifactWithExecuteInSubdir.txt").mode()); |
|
|
} |
|
|
|
|
|
// on master, with flatten |
|
|
{ |
|
|
FreeStyleProject p = createFreeStyleProject(); |
|
|
p.setAssignedNode(jenkins); |
|
|
p.getBuildersList().add(new CopyArtifact( |
|
|
copiee.getFullName(), |
|
|
"", |
|
|
new SpecificBuildSelector(Integer.toString(copieeBuild.getNumber())), |
|
|
"", |
|
|
"", |
|
|
"", |
|
|
true, // flatten |
|
|
false, |
|
|
false |
|
|
)); |
|
|
FreeStyleBuild b = p.scheduleBuild2(0).get(); |
|
|
assertBuildStatusSuccess(b); |
|
|
|
|
|
assertEquals(jenkins, b.getBuiltOn()); |
|
|
|
|
|
FilePath w = b.getWorkspace(); |
|
|
assertEquals(0644, w.child("artifact.txt").mode()); |
|
|
assertEquals(0755, w.child("artifactWithExecute.txt").mode()); |
|
|
assertEquals(0644, w.child("artifactInSubdir.txt").mode()); |
|
|
assertEquals(0755, w.child("artifactWithExecuteInSubdir.txt").mode()); |
|
|
} |
|
|
|
|
|
DumbSlave node = createOnlineSlave(); |
|
|
|
|
|
// on slave, without flatten |
|
|
{ |
|
|
FreeStyleProject p = createFreeStyleProject(); |
|
|
p.setAssignedNode(node); |
|
|
p.getBuildersList().add(new CopyArtifact( |
|
|
copiee.getFullName(), |
|
|
"", |
|
|
new SpecificBuildSelector(Integer.toString(copieeBuild.getNumber())), |
|
|
"", |
|
|
"", |
|
|
"", |
|
|
false, |
|
|
false, |
|
|
false |
|
|
)); |
|
|
FreeStyleBuild b = p.scheduleBuild2(0).get(); |
|
|
assertBuildStatusSuccess(b); |
|
|
|
|
|
assertEquals(node, b.getBuiltOn()); |
|
|
|
|
|
FilePath w = b.getWorkspace(); |
|
|
assertEquals(0644, w.child("artifact.txt").mode()); |
|
|
assertEquals(0755, w.child("artifactWithExecute.txt").mode()); |
|
|
assertEquals(0644, w.child("subdir/artifactInSubdir.txt").mode()); |
|
|
assertEquals(0755, w.child("subdir/artifactWithExecuteInSubdir.txt").mode()); |
|
|
} |
|
|
|
|
|
// on slave, with flatten |
|
|
{ |
|
|
FreeStyleProject p = createFreeStyleProject(); |
|
|
p.setAssignedNode(node); |
|
|
p.getBuildersList().add(new CopyArtifact( |
|
|
copiee.getFullName(), |
|
|
"", |
|
|
new SpecificBuildSelector(Integer.toString(copieeBuild.getNumber())), |
|
|
"", |
|
|
"", |
|
|
"", |
|
|
true, // flatten |
|
|
false, |
|
|
false |
|
|
)); |
|
|
FreeStyleBuild b = p.scheduleBuild2(0).get(); |
|
|
assertBuildStatusSuccess(b); |
|
|
|
|
|
assertEquals(node, b.getBuiltOn()); |
|
|
|
|
|
FilePath w = b.getWorkspace(); |
|
|
assertEquals(0644, w.child("artifact.txt").mode()); |
|
|
assertEquals(0755, w.child("artifactWithExecute.txt").mode()); |
|
|
assertEquals(0644, w.child("artifactInSubdir.txt").mode()); |
|
|
assertEquals(0755, w.child("artifactWithExecuteInSubdir.txt").mode()); |
|
|
} |
|
|
} |
|
|
|
|
|
/* This test is available only for Jenkins >= 1.521. |
|
|
* As I do not upgrade target Jenkins version to preserve compatibility |
|
|
* (the feature supporting QueueItemAuthenticator itself does not need to upgrade target version), |
|
|