Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:jenkinsci/workflow-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Sep 10, 2015
2 parents e8d9820 + f15c497 commit a24f130
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Only noting significant user changes, not internal code cleanups and minor bug fixes.

## 1.11 (not yet released)
* [JENKINS-30346](https://issues.jenkins-ci.org/browse/JENKINS-30346): added a cross platform `deleteDir` step to recursively delete a directory and its contents.

## 1.10 (Aug 31 2015)

* [JENKINS-30122](https://issues.jenkins-ci.org/browse/JENKINS-30122): regression in usage of the Authorize Project plugin in 1.10-beta-1.
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ and browse [localhost:8080](http://localhost:8080/).

Jenkins Workflow: What’s Up? (JUC West) (Sep 2015): [slides](http://www.slideshare.net/jgcloudbees/juc-west-15-jenkins-workflow-whats-up) and accompanying [demo](https://youtu.be/yaEF3VAjWbk)

Jenkins Office Hour on Workflow for plugin developers (Auth 2015): [video](https://www.youtube.com/watch?v=4zdy7XGx3PA)
Jenkins Office Hour on Workflow for plugin developers (Aug 2015): [video](https://www.youtube.com/watch?v=4zdy7XGx3PA)

Workflow Meetup London (Mar 2015): [slides](http://www.slideshare.net/jgcloudbees/london-workflow-summit-kkjg)

Jenkins Workflow Screencast (Jan 2015): [video](https://www.youtube.com/watch?v=Welwf1wTU-w)

Webinar _Orchestrating the Continuous Delivery Process in Jenkins with Workflow_ (Dec 2014): [video](http://youtu.be/ZqfiW8eVcuQ)


# Detailed guides

[Reusing build steps from freestyle projects](basic-steps/CORE-STEPS.md)
Expand Down
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;
}
}
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;

}

}
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"/>

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>

0 comments on commit a24f130

Please sign in to comment.