Search in sources :

Example 36 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project pipeline-aws-plugin by jenkinsci.

the class CFNCreateChangeSetTests method createChangeSetStackFailure.

@Test
public void createChangeSetStackFailure() throws Exception {
    WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
    Mockito.when(stack.exists()).thenReturn(true);
    Mockito.when(stack.describeChangeSet("bar")).thenReturn(new DescribeChangeSetResult().withStatus(ChangeSetStatus.FAILED));
    job.setDefinition(new CpsFlowDefinition("" + "node {\n" + "  cfnCreateChangeSet(stack: 'foo', changeSet: 'bar')\n" + "}\n", true));
    jenkinsRule.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) DescribeChangeSetResult(com.amazonaws.services.cloudformation.model.DescribeChangeSetResult) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 37 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project pipeline-aws-plugin by jenkinsci.

the class CFNCreateChangeSetTests method createChangeSetWithRawTemplate.

@Test
public void createChangeSetWithRawTemplate() throws Exception {
    WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
    Mockito.when(stack.exists()).thenReturn(true);
    Mockito.when(stack.describeChangeSet("bar")).thenReturn(new DescribeChangeSetResult().withChanges(new Change()).withStatus(ChangeSetStatus.CREATE_COMPLETE));
    job.setDefinition(new CpsFlowDefinition("" + "node {\n" + "  def changes = cfnCreateChangeSet(stack: 'foo', changeSet: 'bar', template: 'foobaz')\n" + "  echo \"changesCount=${changes.size()}\"\n" + "}\n", true));
    Run run = jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
    jenkinsRule.assertLogContains("changesCount=1", run);
    PowerMockito.verifyNew(CloudFormationStack.class, Mockito.atLeastOnce()).withArguments(Mockito.any(AmazonCloudFormation.class), Mockito.eq("foo"), Mockito.any(TaskListener.class));
    Mockito.verify(this.stack).createChangeSet(Mockito.eq("bar"), Mockito.eq("foobaz"), Mockito.anyString(), Mockito.anyCollectionOf(Parameter.class), Mockito.anyCollectionOf(Tag.class), Mockito.anyInt(), Mockito.eq(ChangeSetType.UPDATE), Mockito.anyString());
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) TaskListener(hudson.model.TaskListener) Parameter(com.amazonaws.services.cloudformation.model.Parameter) Run(hudson.model.Run) DescribeChangeSetResult(com.amazonaws.services.cloudformation.model.DescribeChangeSetResult) Change(com.amazonaws.services.cloudformation.model.Change) Tag(com.amazonaws.services.cloudformation.model.Tag) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 38 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project pipeline-aws-plugin by jenkinsci.

the class CFNCreateChangeSetTests method createEmptyChangeSet.

@Test
public void createEmptyChangeSet() throws Exception {
    WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
    Mockito.when(stack.exists()).thenReturn(true);
    Mockito.when(stack.describeChangeSet("bar")).thenReturn(new DescribeChangeSetResult().withStatus(ChangeSetStatus.FAILED).withStatusReason("The submitted information didn't contain changes. Submit different information to create a change set."));
    job.setDefinition(new CpsFlowDefinition("" + "node {\n" + "  def changes = cfnCreateChangeSet(stack: 'foo', changeSet: 'bar')\n" + "  echo \"changesCount=${changes.size()}\"\n" + "}\n", true));
    Run run = jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
    jenkinsRule.assertLogContains("changesCount=0", run);
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) Run(hudson.model.Run) DescribeChangeSetResult(com.amazonaws.services.cloudformation.model.DescribeChangeSetResult) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 39 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project pipeline-aws-plugin by jenkinsci.

the class CFNCreateChangeSetTests method createChangeSetStackDoesNotExist.

@Test
public void createChangeSetStackDoesNotExist() throws Exception {
    WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
    Mockito.when(stack.exists()).thenReturn(false);
    Mockito.when(stack.describeChangeSet("bar")).thenReturn(new DescribeChangeSetResult().withChanges(new Change()).withStatus(ChangeSetStatus.CREATE_COMPLETE));
    job.setDefinition(new CpsFlowDefinition("" + "node {\n" + "  def changes = cfnCreateChangeSet(stack: 'foo', changeSet: 'bar')\n" + "  echo \"changesCount=${changes.size()}\"\n" + "}\n", true));
    Run run = jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
    jenkinsRule.assertLogContains("changesCount=1", run);
    PowerMockito.verifyNew(CloudFormationStack.class, Mockito.atLeastOnce()).withArguments(Mockito.any(AmazonCloudFormation.class), Mockito.eq("foo"), Mockito.any(TaskListener.class));
    Mockito.verify(this.stack).createChangeSet(Mockito.eq("bar"), Mockito.anyString(), Mockito.anyString(), Mockito.anyCollectionOf(Parameter.class), Mockito.anyCollectionOf(Tag.class), Mockito.anyInt(), Mockito.eq(ChangeSetType.CREATE), Mockito.anyString());
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) TaskListener(hudson.model.TaskListener) Parameter(com.amazonaws.services.cloudformation.model.Parameter) Run(hudson.model.Run) DescribeChangeSetResult(com.amazonaws.services.cloudformation.model.DescribeChangeSetResult) Change(com.amazonaws.services.cloudformation.model.Change) Tag(com.amazonaws.services.cloudformation.model.Tag) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 40 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project pipeline-aws-plugin by jenkinsci.

the class CFNDeleteStackTests method deleteStack.

@Test
public void deleteStack() throws Exception {
    WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
    job.setDefinition(new CpsFlowDefinition("" + "node {\n" + "  cfnDelete(stack: 'foo')" + "}\n", true));
    this.jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
    PowerMockito.verifyNew(CloudFormationStack.class).withArguments(Mockito.any(AmazonCloudFormation.class), Mockito.eq("foo"), Mockito.any(TaskListener.class));
    Mockito.verify(this.stack).delete(Mockito.anyLong());
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) TaskListener(hudson.model.TaskListener) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)206 Test (org.junit.Test)196 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)168 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)111 Issue (org.jvnet.hudson.test.Issue)63 Map (java.util.Map)60 List (java.util.List)26 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)22 RunList (hudson.util.RunList)20 ExtensionList (hudson.ExtensionList)19 Statement (org.junit.runners.model.Statement)19 Run (hudson.model.Run)17 URL (java.net.URL)16 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)12 TaskListener (hudson.model.TaskListener)11 CpsFlowExecution (org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)10 NodeStepTypePredicate (org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate)9 DescribeChangeSetResult (com.amazonaws.services.cloudformation.model.DescribeChangeSetResult)7 Parameter (com.amazonaws.services.cloudformation.model.Parameter)6