Skip to content

Commit

Permalink
[JENKINS-39438] Do not append -f flag to command when forks is 0. Set…
Browse files Browse the repository at this point in the history
… default forks value to 0 in standard job and pipeline.
  • Loading branch information
jcsirot committed Dec 26, 2016
1 parent ed39f54 commit 281162c
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 7 deletions.
Expand Up @@ -94,12 +94,14 @@ protected ArgumentListBuilder appendInventory(ArgumentListBuilder args)
}

public T setForks(int forks) {
this.forks = forks;
this.forks = Math.max(forks, 0);
return (T) this;
}

public ArgumentListBuilder appendForks(ArgumentListBuilder args) {
args.add("-f").add(forks);
if (forks > 0) {
args.add("-f").add(forks);
}
return args;
}

Expand Down
Expand Up @@ -66,7 +66,7 @@ public class AnsibleAdHocCommandBuilder extends Builder implements SimpleBuildSt

public String sudoUser = "root";

public int forks = 5;
public int forks = 0;

public boolean unbufferedOutput = true;

Expand Down
Expand Up @@ -69,7 +69,7 @@ public class AnsiblePlaybookBuilder extends Builder implements SimpleBuildStep

public String sudoUser = "root";

public int forks = 5;
public int forks = 0;

public boolean unbufferedOutput = true;

Expand Down
Expand Up @@ -70,7 +70,7 @@ public class AnsiblePlaybookStep extends AbstractStepImpl {
private Map extraVars = null;
private String extras = null;
private boolean colorized = false;
private int forks = 5;
private int forks = 0;

@DataBoundConstructor
public AnsiblePlaybookStep(String playbook) {
Expand Down
@@ -1,3 +1,3 @@
<div>
Specify number of parallel processes to use
Specify number of parallel processes to use. Set to 0 to use the default value.
</div>
@@ -1,3 +1,3 @@
<div>
Specify number of parallel processes to use
Specify number of parallel processes to use. Set to 0 to use the default value.
</div>
Expand Up @@ -55,6 +55,28 @@ public void should_generate_simple_invocation() throws Exception {
.isEqualTo("/usr/local/bin/ansible localhost -i /tmp/hosts -m ping -f 5");
}

@Test
public void should_generate_no_forks() throws Exception {
// Given
Inventory inventory = new InventoryPath("/tmp/hosts");
BuildListener listener = mock(BuildListener.class);
CLIRunner runner = mock(CLIRunner.class);
AbstractBuild<?,?> build = mock(AbstractBuild.class);
when(build.getEnvironment(any(TaskListener.class))).thenReturn(new EnvVars());
AnsibleAdHocCommandInvocation invocation = new AnsibleAdHocCommandInvocation("/usr/local/bin/ansible", build, listener);
invocation.setHostPattern("localhost");
invocation.setInventory(inventory);
invocation.setModule("ping");
invocation.setForks(0);
// When
invocation.execute(runner);
// Then
ArgumentCaptor<ArgumentListBuilder> argument = ArgumentCaptor.forClass(ArgumentListBuilder.class);
verify(runner).execute(argument.capture(), anyMap());
assertThat(argument.getValue().toString())
.isEqualTo("/usr/local/bin/ansible localhost -i /tmp/hosts -m ping");
}

@Test
public void should_generate_simple_invocation_with_env() throws Exception {
// Given
Expand Down

0 comments on commit 281162c

Please sign in to comment.