# CodeCommitSourceAction

CodePipeline Source that is provided by an AWS CodeCommit repository.

If the CodeCommit repository is in a different account, you must use
`CodeCommitTrigger.EVENTS` to trigger the pipeline.

(That is because the Pipeline structure normally only has a `RepositoryName`
field, and that is not enough for the pipeline to locate the repository's
source account. However, if the pipeline is triggered via an EventBridge
event, the event itself has the full repository ARN in there, allowing the
pipeline to locate the repository).

Extends: Action › Action › CodeCommitSourceAction
Implements: IAction

- Source: [`aws-codepipeline-actions/lib/codecommit/source-action.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-codepipeline-actions/lib/codecommit/source-action.ts#L156)

## Example

```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,
  ],
});
```

## Initializer

```ts
new CodeCommitSourceAction(props: CodeCommitSourceActionProps)
```

## Properties

- `actionProperties`: [ActionProperties](/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline.ActionProperties.html) — The simple properties of the Action, like its Owner, name, etc.

  Note that this accessor will be called before the `bind` callback.

- `variables`: [CodeCommitSourceVariables](/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline_actions.CodeCommitSourceVariables.html) — The variables emitted by this action.

## Methods

- `bind(scope: Construct, stage: IStage, options: ActionBindOptions): ActionConfig` — The callback invoked when this Action is added to a Pipeline.

- `onStateChange(name: string, target?: IRuleTarget, options?: RuleProps): Rule` — Creates an Event that will be triggered whenever the state of this Action changes.
