Skip to content

Commit

Permalink
Adds unit test for parameter blocks
Browse files Browse the repository at this point in the history
JENKINS-60423 Powershell fails when the script starts with 'CmdletBinding' attribut
  • Loading branch information
froque committed Dec 23, 2022
1 parent 6504b68 commit 29cb70c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/test/java/hudson/plugins/powershell/PowerShellTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,44 @@ public void testBuildSuccess() throws Exception {
r.assertBuildStatusSuccess(build);
}

@Test
public void testBuildParameterBlockWithStopFails() throws Exception {
Assume.assumeTrue(isPowerShellAvailable());

FreeStyleProject project1 = r.createFreeStyleProject("project1");
project1.getBuildersList().add(new PowerShell("param(\n" +
" [Parameter()][String] $Param1 = \"this parameter #1\",\n" +
" [Parameter()][String] $Param2 = \"this parameter #2\"\n" +
")\n" +
"\n" +
"Write-Host $Param1\n" +
"Write-Host $Param2", true, true, null));

QueueTaskFuture<FreeStyleBuild> freeStyleBuildQueueTaskFuture = project1.scheduleBuild2(0);
FreeStyleBuild build = freeStyleBuildQueueTaskFuture.get();

r.assertBuildStatus(Result.FAILURE, build);
}

@Test
public void testBuildParameterBlockWithoutStopSucceeds() throws Exception {
Assume.assumeTrue(isPowerShellAvailable());

FreeStyleProject project1 = r.createFreeStyleProject("project1");
project1.getBuildersList().add(new PowerShell("param(\n" +
" [Parameter()][String] $Param1 = \"this parameter #1\",\n" +
" [Parameter()][String] $Param2 = \"this parameter #2\"\n" +
")\n" +
"\n" +
"Write-Host $Param1\n" +
"Write-Host $Param2", false, true, null));

QueueTaskFuture<FreeStyleBuild> freeStyleBuildQueueTaskFuture = project1.scheduleBuild2(0);
FreeStyleBuild build = freeStyleBuildQueueTaskFuture.get();

r.assertBuildStatusSuccess(build);
}

@Test
public void testBuildBadCommandFails() throws Exception {
Assume.assumeTrue(isPowerShellAvailable());
Expand Down

0 comments on commit 29cb70c

Please sign in to comment.