# CodeCommitSourceActionProps

Construction properties of the `CodeCommitSourceAction CodeCommit source CodePipeline Action`.

Extends: [CommonAwsActionProps](/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline.CommonAwsActionProps.html)
Used as props by: [CodeCommitSourceAction](/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline_actions.CodeCommitSourceAction.html)

- Source: [`aws-codepipeline-actions/lib/codecommit/source-action.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-codepipeline-actions/lib/codecommit/source-action.ts#L91)
- Type last changed: v2.122.0 · 18 Jan 2024

## Example

TypeScript:

```ts
// Source stage: read from repository
const repo = new codecommit.Repository(stack, 'TemplateRepo', {
  repositoryName: 'template-repo',
});
const sourceOutput = new codepipeline.Artifact('SourceArtifact');
const source = new cpactions.CodeCommitSourceAction({
  actionName: 'Source',
  repository: repo,
  output: sourceOutput,
  trigger: cpactions.CodeCommitTrigger.POLL,
});
const sourceStage = {
  stageName: 'Source',
  actions: [source],
};

// Deployment stage: create and deploy changeset with manual approval
const stackName = 'OurStack';
const changeSetName = 'StagedChangeSet';

const prodStage = {
  stageName: 'Deploy',
  actions: [
    new cpactions.CloudFormationCreateReplaceChangeSetAction({
      actionName: 'PrepareChanges',
      stackName,
      changeSetName,
      adminPermissions: true,
      templatePath: sourceOutput.atPath('template.yaml'),
      runOrder: 1,
    }),
    new cpactions.ManualApprovalAction({
      actionName: 'ApproveChanges',
      runOrder: 2,
    }),
    new cpactions.CloudFormationExecuteChangeSetAction({
      actionName: 'ExecuteChanges',
      stackName,
      changeSetName,
      runOrder: 3,
    }),
  ],
};

new codepipeline.Pipeline(stack, 'Pipeline', {
  crossAccountKeys: true,
  stages: [
    sourceStage,
    prodStage,
  ],
});
```

Python:

```python
# Source stage: read from repository
repo = codecommit.Repository(stack, "TemplateRepo",
    repository_name="template-repo"
)
source_output = codepipeline.Artifact("SourceArtifact")
source = cpactions.CodeCommitSourceAction(
    action_name="Source",
    repository=repo,
    output=source_output,
    trigger=cpactions.CodeCommitTrigger.POLL
)
source_stage = {
    "stage_name": "Source",
    "actions": [source]
}

# Deployment stage: create and deploy changeset with manual approval
stack_name = "OurStack"
change_set_name = "StagedChangeSet"

prod_stage = {
    "stage_name": "Deploy",
    "actions": [
        cpactions.CloudFormationCreateReplaceChangeSetAction(
            action_name="PrepareChanges",
            stack_name=stack_name,
            change_set_name=change_set_name,
            admin_permissions=True,
            template_path=source_output.at_path("template.yaml"),
            run_order=1
        ),
        cpactions.ManualApprovalAction(
            action_name="ApproveChanges",
            run_order=2
        ),
        cpactions.CloudFormationExecuteChangeSetAction(
            action_name="ExecuteChanges",
            stack_name=stack_name,
            change_set_name=change_set_name,
            run_order=3
        )
    ]
}

codepipeline.Pipeline(stack, "Pipeline",
    cross_account_keys=True,
    stages=[source_stage, prod_stage
    ]
)
```

Java:

```java
// Source stage: read from repository
Repository repo = Repository.Builder.create(stack, "TemplateRepo")
        .repositoryName("template-repo")
        .build();
Artifact sourceOutput = new Artifact("SourceArtifact");
CodeCommitSourceAction source = CodeCommitSourceAction.Builder.create()
        .actionName("Source")
        .repository(repo)
        .output(sourceOutput)
        .trigger(CodeCommitTrigger.POLL)
        .build();
Map<String, Object> sourceStage = Map.of(
        "stageName", "Source",
        "actions", List.of(source));

// Deployment stage: create and deploy changeset with manual approval
String stackName = "OurStack";
String changeSetName = "StagedChangeSet";

Map<String, Object> prodStage = Map.of(
        "stageName", "Deploy",
        "actions", List.of(
            CloudFormationCreateReplaceChangeSetAction.Builder.create()
                    .actionName("PrepareChanges")
                    .stackName(stackName)
                    .changeSetName(changeSetName)
                    .adminPermissions(true)
                    .templatePath(sourceOutput.atPath("template.yaml"))
                    .runOrder(1)
                    .build(),
            ManualApprovalAction.Builder.create()
                    .actionName("ApproveChanges")
                    .runOrder(2)
                    .build(),
            CloudFormationExecuteChangeSetAction.Builder.create()
                    .actionName("ExecuteChanges")
                    .stackName(stackName)
                    .changeSetName(changeSetName)
                    .runOrder(3)
                    .build()));

Pipeline.Builder.create(stack, "Pipeline")
        .crossAccountKeys(true)
        .stages(List.of(sourceStage, prodStage))
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// Source stage: read from repository
var repo = new Repository(stack, "TemplateRepo", new RepositoryProps {
    RepositoryName = "template-repo"
});
var sourceOutput = new Artifact("SourceArtifact");
var source = new CodeCommitSourceAction(new CodeCommitSourceActionProps {
    ActionName = "Source",
    Repository = repo,
    Output = sourceOutput,
    Trigger = CodeCommitTrigger.POLL
});
IDictionary<string, object> sourceStage = new Dictionary<string, object> {
    { "stageName", "Source" },
    { "actions", new [] { source } }
};

// Deployment stage: create and deploy changeset with manual approval
var stackName = "OurStack";
var changeSetName = "StagedChangeSet";

IDictionary<string, object> prodStage = new Dictionary<string, object> {
    { "stageName", "Deploy" },
    { "actions", new [] {
        new CloudFormationCreateReplaceChangeSetAction(new CloudFormationCreateReplaceChangeSetActionProps {
            ActionName = "PrepareChanges",
            StackName = stackName,
            ChangeSetName = changeSetName,
            AdminPermissions = true,
            TemplatePath = sourceOutput.AtPath("template.yaml"),
            RunOrder = 1
        }),
        new ManualApprovalAction(new ManualApprovalActionProps {
            ActionName = "ApproveChanges",
            RunOrder = 2
        }),
        new CloudFormationExecuteChangeSetAction(new CloudFormationExecuteChangeSetActionProps {
            ActionName = "ExecuteChanges",
            StackName = stackName,
            ChangeSetName = changeSetName,
            RunOrder = 3
        }) } }
};

new Pipeline(stack, "Pipeline", new PipelineProps {
    CrossAccountKeys = true,
    Stages = new [] { sourceStage, prodStage }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// Source stage: read from repository
repo := codecommit.NewRepository(stack, jsii.String("TemplateRepo"), &RepositoryProps{
	RepositoryName: jsii.String("template-repo"),
})
sourceOutput := codepipeline.NewArtifact(jsii.String("SourceArtifact"))
source := cpactions.NewCodeCommitSourceAction(&CodeCommitSourceActionProps{
	ActionName: jsii.String("Source"),
	Repository: repo,
	Output: sourceOutput,
	Trigger: cpactions.CodeCommitTrigger_POLL,
})
sourceStage := map[string]interface{}{
	"stageName": jsii.String("Source"),
	"actions": []CodeCommitSourceAction{
		source,
	},
}

// Deployment stage: create and deploy changeset with manual approval
stackName := "OurStack"
changeSetName := "StagedChangeSet"

prodStage := map[string]interface{}{
	"stageName": jsii.String("Deploy"),
	"actions": []interface{}{
		cpactions.NewCloudFormationCreateReplaceChangeSetAction(&CloudFormationCreateReplaceChangeSetActionProps{
			"actionName": jsii.String("PrepareChanges"),
			"stackName": jsii.String(stackName),
			"changeSetName": jsii.String(changeSetName),
			"adminPermissions": jsii.Boolean(true),
			"templatePath": sourceOutput.atPath(jsii.String("template.yaml")),
			"runOrder": jsii.Number(1),
		}),
		cpactions.NewManualApprovalAction(&ManualApprovalActionProps{
			"actionName": jsii.String("ApproveChanges"),
			"runOrder": jsii.Number(2),
		}),
		cpactions.NewCloudFormationExecuteChangeSetAction(&CloudFormationExecuteChangeSetActionProps{
			"actionName": jsii.String("ExecuteChanges"),
			"stackName": jsii.String(stackName),
			"changeSetName": jsii.String(changeSetName),
			"runOrder": jsii.Number(3),
		}),
	},
}

codepipeline.NewPipeline(stack, jsii.String("Pipeline"), &PipelineProps{
	CrossAccountKeys: jsii.Boolean(true),
	Stages: []StageProps{
		sourceStage,
		prodStage,
	},
})
```

## Properties

- `actionName`: string (required) — The physical, human-readable name of the Action.

  Note that Action names must be unique within a single Stage.

- `branch`: string = 'master'

- `codeBuildCloneOutput`: boolean = false — Whether the output should be the contents of the repository (which is the default), or a link that allows CodeBuild to clone the repository before building.

  **Note**: if this option is true,
  then only CodeBuild actions can use the resulting `output`.

- `customEventRule`: [ICustomEventRule](/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline_actions.ICustomEventRule.html) — You can pass a `customEventRule` to set up a custom event rule for the CodeCommit source action.

  **Default:** Event rule which is triggered by CodeCommit repository on commit

  You must provide the `eventPattern` and `target` properties in the `customEventRule` object.
  Check which `eventPattern` to use: https://docs.aws.amazon.com/codecommit/latest/userguide/monitoring-events.html

- `eventRole`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — Role to be used by on commit event rule.

  **Default:** a new role will be created.

  Used only when trigger value is CodeCommitTrigger.EVENTS.

- `output`: [Artifact](/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline.Artifact.html) (required)

- `repository`: [IRepository](/cdk/api/v2/docs/aws-cdk-lib.aws_codecommit.IRepository.html) (required) — The CodeCommit repository.

- `role`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The Role in which context's this Action will be executing in.

  **Default:** a new Role will be generated

  The Pipeline's Role will assume this Role
  (the required permissions for that will be granted automatically)
  right before executing this Action.
  This Action will be passed into your `IAction.bind`
  method in the `ActionBindOptions.role` property.

- `runOrder`: number = 1 — The runOrder property for this Action.

  RunOrder determines the relative order in which multiple Actions in the same Stage execute.

- `trigger`: [CodeCommitTrigger](/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline_actions.CodeCommitTrigger.html) = CodeCommitTrigger.EVENTS — How should CodePipeline detect source changes for this Action.

- `variablesNamespace`: string — The name of the namespace to use for variables emitted by this action.

  **Default:** a name will be generated, based on the stage and action names, if any of the action's variables were referenced - otherwise, no namespace will be set
