Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a44d227
[JENKINS-62014] Add support for global build step env var filters
daniel-beck Jul 24, 2020
3337702
Fix SpotBugs issues
daniel-beck Jul 27, 2020
9731ae7
Fix dependencies
daniel-beck Aug 12, 2020
4877c2c
[JENKINS-62014] Add smoke test for env var filters
dwnusbaum Aug 12, 2020
bea22a5
Update to generic-environment-filters 1.2 for the test
daniel-beck Aug 13, 2020
8549da1
Ensure the correct types are being listed
daniel-beck Aug 13, 2020
a557f2a
Update dependency versions to be compatible
daniel-beck Aug 13, 2020
cc10978
Add JUnit to test dependencies, required by matrix-project
daniel-beck Aug 13, 2020
cc3d063
Use plugin BOM to update dependencies
dwnusbaum Aug 13, 2020
8bca029
Don't run a CI build on Windows on Java 11
dwnusbaum Aug 13, 2020
90a4290
Fix ShellStepTest.envVarFilters on Windows
dwnusbaum Aug 13, 2020
d0ae1e8
Fix syntax error in test Pipeline in ShellStepTest.envVarFilters
dwnusbaum Aug 13, 2020
8cbe08d
Add sleeps to give sh steps in flaky tests time to suspend before age…
dwnusbaum Aug 13, 2020
d8829d5
Revert "Add sleeps to give sh steps in flaky tests time to suspend be…
dwnusbaum Aug 13, 2020
f24fffa
Add sleep to the end of ShellStepTest.abort on Windows
dwnusbaum Aug 13, 2020
1870855
Try to get better diagnostic info from ShellStepTest.abort
dwnusbaum Aug 13, 2020
19514f5
ci.jenkins.io Windows agents are too old for timeout?
dwnusbaum Aug 13, 2020
e1e3c60
Ignore flaky tests while trying to diagnose ShellStepTest.abort
dwnusbaum Aug 13, 2020
0ccf328
Add some calls to println to see where test is really failing
dwnusbaum Aug 13, 2020
e93416f
Revert diagnostic changes and pull in jenkins-test-harness update to …
dwnusbaum Aug 14, 2020
a18e18b
Revert additional changes
dwnusbaum Aug 14, 2020
183d623
Wait for build to complete before checking that process is completed …
dwnusbaum Aug 14, 2020
8e76fc8
Unignore flaky tests to try to diagnose the problem
dwnusbaum Aug 14, 2020
823399a
Wait to kill agents in disconnection-related tests until after log ou…
dwnusbaum Aug 14, 2020
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']
])
42 changes: 24 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,56 @@
<properties>
<revision>2.36</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.176.1</jenkins.version>
<jenkins.version>2.248</jenkins.version>
<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>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-test-harness</artifactId>
<version>2.67-rc1366.8aea7be00cd5</version> <!-- TODO: https://github.com/jenkinsci/jenkins-test-harness/pull/236 -->
</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 +125,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,14 +733,45 @@ 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.
*/
private <T> void ensureForWhile(int timeout, T o, Predicate<T> predicate) throws Exception {
long goal = System.currentTimeMillis()+timeout;
while (System.currentTimeMillis()<goal) {
if (!predicate.test(o))
if (!predicate.test(o)) {
throw new AssertionError(predicate);
}
Thread.sleep(100);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
import static org.junit.Assert.*;
import org.junit.Assume;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -339,13 +340,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 +394,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 +403,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