Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
buildPlugin(useAci: true, configurations: [
[platform: 'linux', jdk: '8'],
[platform: 'windows', jdk: '8'],
[platform: 'linux', jdk: '11'],
[platform: 'windows', jdk: '11']
[platform: 'linux', jdk: '11']
])
37 changes: 19 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.54</version>
<version>4.6</version>
<relativePath />
</parent>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand Down Expand Up @@ -64,49 +64,51 @@
<properties>
<revision>2.36</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.176.1</jenkins.version>
<jenkins.version>2.248</jenkins.version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I guess because of the new interface there is no way to get things working on older versions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it uses a new core type that was added in this core release. But the feature supported here is only available starting with this core release anyway, so that's not a problem.

Supporting older baselines in this plugin might require backports etc. though, so I can understand if you want to hold off the merge for a bit longer.

<java.level>8</java.level>
<useBeta>true</useBeta>
<workflow-step-api-plugin.version>2.20</workflow-step-api-plugin.version>
<workflow-support-plugin.version>3.3</workflow-support-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.235.x</artifactId>
<version>11</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>${workflow-step-api-plugin.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>durable-task</artifactId>
<version>1.33</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>2.33</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>${workflow-support-plugin.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>2.70</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>2.31</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>2.14</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -118,43 +120,42 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>${workflow-step-api-plugin.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>${workflow-support-plugin.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials-binding</artifactId>
<version>1.17</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-scm-step</artifactId>
<version>2.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
<version>1.58</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>1.18</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>generic-environment-filters</artifactId>
<version>1.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import hudson.init.Terminator;
import hudson.model.Node;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.remoting.Channel;
import hudson.remoting.ChannelClosedException;
Expand All @@ -61,6 +62,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import jenkins.model.Jenkins;
import jenkins.tasks.filters.EnvVarsFilterableBuilder;
import jenkins.util.Timer;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -96,7 +98,7 @@
* When the process exits, the status code is also written to a file and ultimately results in the step passing or failing.
* <p>Tasks can also be run on the master node, which differs only in that there is no possibility of a network failure.
*/
public abstract class DurableTaskStep extends Step {
public abstract class DurableTaskStep extends Step implements EnvVarsFilterableBuilder {

private static final Logger LOGGER = Logger.getLogger(DurableTaskStep.class.getName());

Expand Down Expand Up @@ -312,6 +314,7 @@ static final class Execution extends AbstractStepExecutionImpl implements Runnab
durableTask.defaultCharset();
}
Launcher launcher = context.get(Launcher.class);
launcher.prepareFilterRules(context.get(Run.class), step);
LOGGER.log(Level.FINE, "launching task against {0} using {1}", new Object[] {ws.getChannel(), launcher});
try {
controller = durableTask.launch(context.get(EnvVars.class), ws, launcher, listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,9 @@ private final class PlaceholderExecutable implements ContinuableExecutable, Acce
FilePath workspace = lease.path;
// Cf. AbstractBuild.getEnvironment:
env.put("WORKSPACE", workspace.getRemote());
if (workspace.getParent() != null) {
env.put("WORKSPACE_TMP", WorkspaceList.tempDir(workspace).getRemote()); // JENKINS-60634
final FilePath tempDir = WorkspaceList.tempDir(workspace);
if (tempDir != null) {
env.put("WORKSPACE_TMP", tempDir.getRemote()); // JENKINS-60634
}
FlowNode flowNode = context.get(FlowNode.class);
if (flowNode != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ public boolean start() throws Exception {
getContext().get(TaskListener.class).getLogger().println("Running in " + workspace);
Map<String, String> env = new HashMap<>();
env.put("WORKSPACE", workspace.getRemote());
if (workspace.getParent() != null) {
env.put("WORKSPACE_TMP", WorkspaceList.tempDir(workspace).getRemote());
final FilePath tempDir = WorkspaceList.tempDir(workspace);
if (tempDir != null) {
env.put("WORKSPACE_TMP", tempDir.getRemote());
}
getContext().newBodyInvoker()
.withContexts(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import hudson.model.BooleanParameterDefinition;
import hudson.model.BooleanParameterValue;
import hudson.model.BuildListener;
import hudson.model.Descriptor;
import hudson.model.FreeStyleProject;
import hudson.model.Node;
import hudson.model.ParametersAction;
Expand All @@ -32,6 +33,9 @@
import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.tasks.BatchFile;
import hudson.tasks.Shell;
import io.jenkins.plugins.environment_filter_utils.util.BuilderUtil;
import io.jenkins.plugins.generic_environment_filters.RemoveSpecificVariablesFilter;
import io.jenkins.plugins.generic_environment_filters.VariableContributingFilter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
Expand All @@ -54,10 +58,13 @@
import java.util.logging.Level;
import java.util.logging.LogRecord;
import javax.annotation.CheckForNull;
import jenkins.tasks.filters.EnvVarsFilterGlobalConfiguration;
import jenkins.util.JenkinsJVM;
import org.apache.commons.lang.StringUtils;

import static org.hamcrest.Matchers.*;

import org.hamcrest.MatcherAssert;
import org.jenkinsci.plugins.durabletask.FileMonitoringTask;

import org.jenkinsci.plugins.workflow.actions.ArgumentsAction;
Expand Down Expand Up @@ -192,6 +199,10 @@ public void abort() throws Exception {

b.getExecutor().interrupt();

// It can take a while for the process to exit on Windows (see JENKINS-59152), so we wait for the build to
// complete and confirm that the process is no longer running after the build has already completed.
j.assertBuildStatus(Result.ABORTED, j.waitForCompletion(b));

// touching should have stopped
final long refTimestamp = Files.getLastModifiedTime(tmp).toMillis();
ensureForWhile(5000, tmp, tmpFile -> {
Expand All @@ -201,8 +212,6 @@ public void abort() throws Exception {
throw new UncheckedIOException(e);
}
});

j.assertBuildStatus(Result.ABORTED, j.waitForCompletion(b));
}

@Issue("JENKINS-41339")
Expand Down Expand Up @@ -724,6 +733,36 @@ private static final class HelloNote extends ConsoleNote<Run<?, ?>> {
j.waitForMessage("Timeout has been exceeded", b); // TODO assertLogContains fails unless a sleep is introduced; possible race condition in waitForCompletion
}

@Issue("JENKINS-62014")
@Test public void envVarFilters() throws Exception {
EnvVarsFilterGlobalConfiguration.getAllActivatedGlobalRules().add(new RemoveSpecificVariablesFilter("FOO"));
EnvVarsFilterGlobalConfiguration.getAllActivatedGlobalRules().add(new VariableContributingFilter("BAZ", "QUX"));
WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"node() {\n" +
" withEnv(['FOO=BAR']) {\n" +
" if (isUnix()) {\n" +
" sh('echo FOO=$FOO and BAZ=$BAZ')\n" +
" } else {\n" +
" bat('ECHO FOO=%FOO% and BAZ=%BAZ%')\n" +
" }\n" +
" }\n" +
"}", true));
WorkflowRun b = j.buildAndAssertSuccess(p);
j.assertLogContains("FOO=", b);
j.assertLogNotContains("FOO=BAR", b);
j.assertLogContains("BAZ=QUX", b);
}

@Issue("JENKINS-62014")
@Test public void ensureTypes() throws Exception {
final List<Descriptor> descriptors = BuilderUtil.allDescriptors();

MatcherAssert.assertThat(descriptors , containsInAnyOrder(
j.jenkins.getDescriptor(Shell.class), j.jenkins.getDescriptor(BatchFile.class),
j.jenkins.getDescriptor(BatchScriptStep.class), j.jenkins.getDescriptor(PowershellScriptStep.class), j.jenkins.getDescriptor(ShellStep.class), j.jenkins.getDescriptor(PowerShellCoreScriptStep.class)));
}

/**
* Asserts that the predicate remains true up to the given timeout.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,14 @@ private void startJnlpProc() throws Exception {
new FileOutputStream(f1).close();
p.setDefinition(new CpsFlowDefinition(
"node('dumbo') {\n" +
" sh 'touch \"" + f2 + "\"; while [ -f \"" + f1 + "\" ]; do sleep 1; done; echo finished waiting; rm \"" + f2 + "\"'\n" +
" sh 'touch \"" + f2 + "\"; while [ -f \"" + f1 + "\" ]; do echo waiting; sleep 1; done; echo finished waiting; rm \"" + f2 + "\"'\n" +
" echo 'OK, done'\n" +
"}", true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
while (!f2.isFile()) {
Thread.sleep(100);
}
story.j.waitForMessage("waiting", b);
assertTrue(b.isBuilding());
Computer c = s.toComputer();
assertNotNull(c);
Expand Down Expand Up @@ -392,7 +393,7 @@ public void evaluate() throws Throwable {
new FileOutputStream(f1).close();
p.setDefinition(new CpsFlowDefinition(
"node('dumbo') {\n" +
" sh 'touch \"" + f2 + "\"; while [ -f \"" + f1 + "\" ]; do sleep 1; done; echo finished waiting; rm \"" + f2 + "\"'\n" +
" sh 'touch \"" + f2 + "\"; while [ -f \"" + f1 + "\" ]; do echo waiting; sleep 1; done; echo finished waiting; rm \"" + f2 + "\"'\n" +
" sh 'echo Back again'\n" +
" echo 'OK, done'\n" +
"}", true));
Expand All @@ -401,6 +402,7 @@ public void evaluate() throws Throwable {
while (!f2.isFile()) {
Thread.sleep(100);
}
story.j.waitForMessage("waiting", b);
LOGGER.info("f2 created, first sh running");
assertTrue(b.isBuilding());
Computer computer = s.toComputer();
Expand Down