use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project pipeline-aws-plugin by jenkinsci.
the class UpdateTrustPolicyStepTests method updateTrustPolicy.
@Test
public void updateTrustPolicy() throws Exception {
WorkflowJob job = this.jenkinsRule.jenkins.createProject(WorkflowJob.class, "updateTest");
Mockito.when(this.iam.updateAssumeRolePolicy(Mockito.any(UpdateAssumeRolePolicyRequest.class))).thenReturn(new UpdateAssumeRolePolicyResult());
job.setDefinition(new CpsFlowDefinition("" + "node {\n" + " writeFile(file: 'testfile', text: '{}')\n" + " updateTrustPolicy(roleName: 'testRole', policyFile: 'testfile')\n" + "}\n", true));
this.jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
Mockito.verify(this.iam).updateAssumeRolePolicy(new UpdateAssumeRolePolicyRequest().withRoleName("testRole").withPolicyDocument("{}"));
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project pipeline-aws-plugin by jenkinsci.
the class WithAWSStepTest method testStepWithGlobalCredentials.
@Test
public void testStepWithGlobalCredentials() throws Exception {
String globalCredentialsId = "global-aws-creds";
List<String> credentialIds = new ArrayList<>();
credentialIds.add(globalCredentialsId);
StandardUsernamePasswordCredentials key = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, globalCredentialsId, "test-global-creds", "global-aws-access-key-id", "global-aws-secret-access-key");
SystemCredentialsProvider.getInstance().getCredentials().add(key);
SystemCredentialsProvider.getInstance().save();
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "testStepWithGlobalCredentials");
job.setDefinition(new CpsFlowDefinition("" + "node {\n" + " withAWS (credentials: '" + globalCredentialsId + "') {\n" + " echo 'It works!'\n" + " }\n" + "}\n", true));
jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project pipeline-aws-plugin by jenkinsci.
the class WithAWSStepTest method testStepWithFolderCredentials.
@Test
public void testStepWithFolderCredentials() throws Exception {
String folderCredentialsId = "folders-aws-creds";
// Create a folder with credentials in its store
Folder folder = jenkinsRule.jenkins.createProject(Folder.class, "folder" + jenkinsRule.jenkins.getItems().size());
CredentialsStore folderStore = this.getFolderStore(folder);
StandardUsernamePasswordCredentials inFolderCredentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, folderCredentialsId, "test-folder-creds", "folder-aws-access-key-id", "folder-aws-secret-access-key");
folderStore.addCredentials(Domain.global(), inFolderCredentials);
SystemCredentialsProvider.getInstance().save();
List<String> credentialIds = new ArrayList<>();
credentialIds.add(folderCredentialsId);
WorkflowJob job = folder.createProject(WorkflowJob.class, "testStepWithFolderCredentials");
job.setDefinition(new CpsFlowDefinition("" + "node {\n" + " withAWS (credentials: '" + folderCredentialsId + "') {\n" + " echo 'It works!'\n" + " }\n" + "}\n", true));
jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project pipeline-aws-plugin by jenkinsci.
the class CFNCreateChangeSetTests method createChangeSetStackExists.
@Test
public void createChangeSetStackExists() 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')\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.UPDATE), Mockito.anyString());
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project pipeline-aws-plugin by jenkinsci.
the class CFNCreateChangeSetTests method createChangeSetStackParametersFromMap.
@Test
public void createChangeSetStackParametersFromMap() 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', params: ['foo': 'bar', 'baz': 'true'])\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.eq(Arrays.asList(new Parameter().withParameterKey("foo").withParameterValue("bar"), new Parameter().withParameterKey("baz").withParameterValue("true"))), Mockito.anyCollectionOf(Tag.class), Mockito.anyInt(), Mockito.eq(ChangeSetType.UPDATE), Mockito.anyString());
}
Aggregations