This repository has been archived by the owner on Dec 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 902
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:jenkinsci/workflow-plugin
- Loading branch information
Showing
6 changed files
with
234 additions
and
1 deletion.
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
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
117 changes: 117 additions & 0 deletions
117
aggregator/src/test/java/org/jenkinsci/plugins/workflow/steps/DeleteDirStepTest.java
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 |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2015 CLoudbees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package org.jenkinsci.plugins.workflow.steps; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; | ||
import org.jenkinsci.plugins.workflow.job.WorkflowJob; | ||
import org.jenkinsci.plugins.workflow.job.WorkflowRun; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import hudson.FilePath; | ||
import hudson.model.queue.QueueTaskFuture; | ||
|
||
public class DeleteDirStepTest { | ||
|
||
@Rule | ||
public JenkinsRule r = new JenkinsRule(); | ||
|
||
@Test | ||
public void testDeleteEmptyWorkspace() throws Exception { | ||
String workspace = runAndGetWorkspaceDir( | ||
"node {\n" + | ||
" deleteDir()\n" + | ||
"}"); | ||
File f = new File(workspace); | ||
Assert.assertFalse("Workspace directory should no longer exist", f.exists()); | ||
} | ||
|
||
@Test | ||
public void testDeleteTopLevelDir() throws Exception { | ||
String workspace = runAndGetWorkspaceDir( | ||
"node {\n" + | ||
" writeFile file: 'f1', text: 'some text'\n" + | ||
" writeFile file: 'f2', text: 'some text'\n" + | ||
" writeFile file: '.hidden', text: 'some text'\n" + | ||
" writeFile file: 'sub1/f1', text: 'some text'\n" + | ||
" writeFile file: '.sub2/f2', text: 'some text'\n" + | ||
" writeFile file: '.sub3/.hidden', text: 'some text'\n" + | ||
" echo 'workspace is ---' + pwd() + '---'\n" + | ||
" deleteDir()\n" + | ||
"}"); | ||
File f = new File(workspace); | ||
Assert.assertFalse("Workspace directory should no longer exist", f.exists()); | ||
} | ||
|
||
@Test | ||
public void testDeleteSubFolder() throws Exception { | ||
String workspace = runAndGetWorkspaceDir( | ||
"node {\n" + | ||
" writeFile file: 'f1', text: 'some text'\n" + | ||
" writeFile file: 'f2', text: 'some text'\n" + | ||
" writeFile file: '.hidden', text: 'some text'\n" + | ||
" writeFile file: 'sub1/f1', text: 'some text'\n" + | ||
" writeFile file: '.sub2/f2', text: 'some text'\n" + | ||
" writeFile file: '.sub3/.hidden', text: 'some text'\n" + | ||
" echo 'workspace is ---' + pwd() + '---'\n" + | ||
" dir ('sub1') {\n" + | ||
" deleteDir()\n" + | ||
" }" + | ||
"}"); | ||
|
||
File f = new File(workspace); | ||
Assert.assertTrue("Workspace directory should still exist", f.exists()); | ||
Assert.assertTrue("f1 should still exist", new File(f, "f1").exists()); | ||
Assert.assertTrue("f1 should still exist", new File(f, "f2").exists()); | ||
Assert.assertFalse("sub1 should not exist", new File(f, "sub1").exists()); | ||
Assert.assertTrue(".sub2/f2 should still exist", new File(f, ".sub2/f2").exists()); | ||
Assert.assertTrue(".sub3/.hidden should still exist", new File(f, ".sub3/.hidden").exists()); | ||
} | ||
|
||
|
||
/** | ||
* Runs the given flow and returns the workspace used. | ||
* @param flow a flow definition. | ||
* @return the workspace used. | ||
*/ | ||
private String runAndGetWorkspaceDir(String flow) throws Exception { | ||
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p"); | ||
|
||
p.setDefinition(new CpsFlowDefinition(flow)); | ||
r.assertBuildStatusSuccess(p.scheduleBuild2(0)); | ||
|
||
FilePath ws = r.jenkins.getWorkspaceFor(p); | ||
String workspace = ws.getRemote(); | ||
Assert.assertNotNull("Unable to locate workspace", workspace); | ||
return workspace; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
basic-steps/src/main/java/org/jenkinsci/plugins/workflow/steps/DeleteDirStep.java
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2015 Cloudbees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package org.jenkinsci.plugins.workflow.steps; | ||
|
||
import hudson.Extension; | ||
import hudson.FilePath; | ||
|
||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
/** | ||
* Simple step that will wipe out the current working directory in a workflows workspace. | ||
*/ | ||
public final class DeleteDirStep extends AbstractStepImpl { | ||
|
||
|
||
@DataBoundConstructor | ||
public DeleteDirStep() { | ||
} | ||
|
||
@Extension | ||
public static final class DescriptorImpl extends AbstractStepDescriptorImpl { | ||
|
||
public DescriptorImpl() { | ||
super(Execution.class); | ||
} | ||
|
||
@Override | ||
public String getFunctionName() { | ||
return "deleteDir"; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Recursively delete the current directory from the workspace"; | ||
} | ||
|
||
} | ||
|
||
public static final class Execution extends AbstractSynchronousNonBlockingStepExecution<Void> { | ||
|
||
@StepContextParameter | ||
private transient FilePath cwd; | ||
|
||
@Override | ||
protected Void run() throws Exception { | ||
cwd.deleteRecursive(); | ||
return null; | ||
} | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...-steps/src/main/resources/org/jenkinsci/plugins/workflow/steps/DeleteDirStep/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
The MIT License | ||
Copyright 2015 Cloudbees, Inc. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
--> | ||
|
||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core"/> | ||
|
6 changes: 6 additions & 0 deletions
6
basic-steps/src/main/resources/org/jenkinsci/plugins/workflow/steps/DeleteDirStep/help.html
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div> | ||
Recursively deletes the current directory and its contents. | ||
Symbolic links and junctions will not be followed but will be removed. | ||
To delete a specific directory of a workspace wrap the <code>deleteDir</code> | ||
step in a <code>dir</code> step. | ||
</div> |