Skip to content
Permalink
Browse files

[JENKINS-27152] Option for pwd step to return temp directory.

  • Loading branch information
jglick committed Mar 1, 2016
1 parent 7d2004e commit 8c74333321f007e829b2a9581af643b792ef47a6
@@ -2,6 +2,10 @@

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

## 1.15 (upcoming)

* [JENKINS-27152](https://issues.jenkins-ci.org/browse/JENKINS-27152): offering `tmp` option to `pwd` step.

## 1.14 (Feb 25 2016)

* [JENKINS-32727](https://issues.jenkins-ci.org/browse/JENKINS-32727): new facility to replay Pipeline builds with a modified script.
@@ -24,6 +24,8 @@

package org.jenkinsci.plugins.workflow.steps;

import hudson.FilePath;
import hudson.slaves.WorkspaceList;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.junit.Test;
@@ -36,8 +38,19 @@

@Test public void basics() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node {echo \"cwd=${pwd()}\"}", true));
r.assertLogContains("cwd=" + r.jenkins.getWorkspaceFor(p), r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
p.setDefinition(new CpsFlowDefinition("node {echo \"cwd='${pwd()}'\"}", true));
r.assertLogContains("cwd='" + r.jenkins.getWorkspaceFor(p) + "'", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}

// TODO use https://github.com/jenkinsci/jenkins/pull/2066
private static FilePath tempDir(FilePath ws) {
return ws.sibling(ws.getName() + System.getProperty(WorkspaceList.class.getName(), "@") + "tmp");
}

@Test public void tmp() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node {echo \"tmp='${pwd tmp: true}'\"}", true));
r.assertLogContains("tmp='" + tempDir(r.jenkins.getWorkspaceFor(p)) + "'", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}

}
@@ -24,9 +24,12 @@

package org.jenkinsci.plugins.workflow.steps;

import com.google.inject.Inject;
import hudson.Extension;
import hudson.FilePath;
import hudson.slaves.WorkspaceList;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

/**
* Returns the working directory path.
@@ -40,8 +43,19 @@
* </pre>
*/
public class PwdStep extends AbstractStepImpl {

private boolean tmp;

@DataBoundConstructor public PwdStep() {}

public boolean isTmp() {
return tmp;
}

@DataBoundSetter public void setTmp(boolean tmp) {
this.tmp = tmp;
}

@Extension public static final class DescriptorImpl extends AbstractStepDescriptorImpl {

public DescriptorImpl() {
@@ -58,12 +72,18 @@ public DescriptorImpl() {

}

// TODO use https://github.com/jenkinsci/jenkins/pull/2066
private static FilePath tempDir(FilePath ws) {
return ws.sibling(ws.getName() + System.getProperty(WorkspaceList.class.getName(), "@") + "tmp");
}

public static class Execution extends AbstractSynchronousStepExecution<String> {

@StepContextParameter private transient FilePath cwd;
@Inject(optional=true) private transient PwdStep step;

@Override protected String run() throws Exception {
return cwd.getRemote();
return (step.isTmp() ? tempDir(cwd) : cwd).getRemote();
}

private static final long serialVersionUID = 1L;
@@ -24,4 +24,8 @@ THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core"/>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:entry field="tmp" title="Temporary directory">
<f:checkbox/>
</f:entry>
</j:jelly>
@@ -0,0 +1,5 @@
<div>
If selected, return a temporary directory associated with the workspace rather than the workspace itself.
This is an appropriate place to put temporary files which should not clutter a source checkout;
local repositories or caches; etc.
</div>

0 comments on commit 8c74333

Please sign in to comment.
You can’t perform that action at this time.