Skip to content
Permalink
Browse files

[JENKINS-39438] Do not append -f flag to command when forks is 0. Set…

… default forks value to 0 in standard job and pipeline.
  • Loading branch information...
jcsirot committed Dec 26, 2016
1 parent ed39f54 commit 281162c0d1ffa5f36dc925611fdec9d8fb7c3cee
@@ -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;
}

@@ -66,7 +66,7 @@

public String sudoUser = "root";

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

public boolean unbufferedOutput = true;

@@ -69,7 +69,7 @@

public String sudoUser = "root";

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

public boolean unbufferedOutput = true;

@@ -70,7 +70,7 @@
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) {
@@ -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>
@@ -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

0 comments on commit 281162c

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