# CodePipelineSource

Factory for CodePipeline source steps.

This class contains a number of factory methods for the different types
of sources that CodePipeline supports.

Extends: Step › CodePipelineSource
Implements: ICodePipelineActionFactory, IFileSetProducer

- Source: [`pipelines/lib/codepipeline/codepipeline-source.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline-source.ts#L21)
- Type last changed: v2.234.0 · 8 Jan 2026

## Example

```ts
// Access the CommitId of a GitHub source in the synth
const source = pipelines.CodePipelineSource.gitHub('owner/repo', 'main');

const pipeline = new pipelines.CodePipeline(scope, 'MyPipeline', {
  synth: new pipelines.ShellStep('Synth', {
    input: source,
    commands: [],
    env: {
      'COMMIT_ID': source.sourceAttribute('CommitId'),
    }
  })
});
```

## Initializer

```ts
new CodePipelineSource(id: string)
```

## Properties

- `consumedStackOutputs`: [StackOutputReference](/cdk/api/v2/docs/aws-cdk-lib.pipelines.StackOutputReference.html)[] (required) — StackOutputReferences this step consumes.

- `dependencies`: [Step](/cdk/api/v2/docs/aws-cdk-lib.pipelines.Step.html)[] (required) — Return the steps this step depends on, based on the FileSets it requires.

- `dependencyFileSets`: [FileSet](/cdk/api/v2/docs/aws-cdk-lib.pipelines.FileSet.html)[] (required) — The list of FileSets consumed by this Step.

- `id`: string (required) — Identifier for this step.

- `isSource`: boolean (required) — Whether or not this is a Source step.

  What it means to be a Source step depends on the engine.

- `primaryOutput`: [FileSet](/cdk/api/v2/docs/aws-cdk-lib.pipelines.FileSet.html) — The primary FileSet produced by this Step.

  Not all steps produce an output FileSet--if they do
  you can substitute the `Step` object for the `FileSet` object.

## Methods

- `addStepDependency(step: Step): void` — Add a dependency on another step.

- `codeCommit(repository: IRepository, branch: string, props?: CodeCommitSourceOptions): CodePipelineSource // chainable` (static) — Returns a CodeCommit source.

  If you need access to symlinks or the repository history, be sure to set
  `codeBuildCloneOutput`.

  **Parameters**

  - `repository` — The CodeCommit repository.
  - `branch` — The branch to use.
  - `props` — The source properties.

  ```ts
  declare const repository: codecommit.IRepository;
  pipelines.CodePipelineSource.codeCommit(repository, 'main');
  ```

- `connection(repoString: string, branch: string, props: ConnectionSourceOptions): CodePipelineSource // chainable` (static) — Returns a CodeStar connection source.

  A CodeStar connection allows AWS CodePipeline to
  access external resources, such as repositories in GitHub, GitHub Enterprise or
  BitBucket.

  To use this method, you first need to create a CodeStar connection
  using the AWS console. In the process, you may have to sign in to the external provider
  -- GitHub, for example -- to authorize AWS to read and modify your repository.
  Once you have done this, copy the connection ARN and use it to create the source.

  Example:

  ```ts
  pipelines.CodePipelineSource.connection('owner/repo', 'main', {
    connectionArn: 'arn:aws:codestar-connections:us-east-1:222222222222:connection/7d2469ff-514a-4e4f-9003-5ca4a43cdc41', // Created using the AWS console
  });
  ```

  If you need access to symlinks or the repository history, be sure to set
  `codeBuildCloneOutput`.

  **Parameters**

  - `repoString` — A string that encodes owner and repository separated by a slash (e.g. 'owner/repo'). The provided string must be resolvable at runtime.
  - `branch` — The branch to use.
  - `props` — The source properties, including the connection ARN.

- `ecr(repository: IRepositoryRef, props?: ECRSourceOptions): CodePipelineSource // chainable` (static) — Returns an ECR source.

  **Parameters**

  - `repository` — The repository that will be watched for changes.
  - `props` — The options, which include the image tag to be checked for changes.

  ```ts
  declare const repository: ecr.IRepository;
  pipelines.CodePipelineSource.ecr(repository, {
    imageTag: 'latest',
  });
  ```

- `gitHub(repoString: string, branch: string, props?: GitHubSourceOptions): CodePipelineSource // chainable` (static) — Returns a GitHub source, using OAuth tokens to authenticate with GitHub and a separate webhook to detect changes.

  This is no longer
  the recommended method. Please consider using `connection()`
  instead.

  Pass in the owner and repository in a single string, like this:

  ```ts
  pipelines.CodePipelineSource.gitHub('owner/repo', 'main');
  ```

  Authentication will be done by a secret called `github-token` in AWS
  Secrets Manager (unless specified otherwise).

  If you rotate the value in the Secret, you must also change at least one property
  on the Pipeline, to force CloudFormation to re-read the secret.

  The token should have these permissions:

  * **repo** - to read the repository
  * **admin:repo_hook** - if you plan to use webhooks (true by default)

  If you need access to symlinks or the repository history, use a source of type
  `connection` instead.

- `produceAction(stage: IStage, options: ProduceActionOptions): CodePipelineActionFactoryResult` — Create the desired Action and add it to the pipeline.

- `s3(bucket: IBucket, objectKey: string, props?: S3SourceOptions): CodePipelineSource // chainable` (static) — Returns an S3 source.

  **Parameters**

  - `bucket` — The bucket where the source code is located.
  - `props` — The options, which include the key that identifies the source code file and and how the pipeline should be triggered.

  ```ts
  declare const bucket: s3.Bucket;
  pipelines.CodePipelineSource.s3(bucket, 'path/to/file.zip');
  ```

- `sequence(steps: Step[]): Step[]` (static) — Define a sequence of steps to be executed in order.

  If you need more fine-grained step ordering, use the `addStepDependency()`
  API. For example, if you want `secondStep` to occur after `firstStep`, call
  `secondStep.addStepDependency(firstStep)`.

- `sourceAttribute(name: string): string` — Return an attribute of the current source revision.

  These values can be passed into the environment variables of pipeline steps,
  so your steps can access information about the source revision.

  Pipeline synth step has some source attributes predefined in the environment.
  If these suffice, you don't need to use this method for the synth step.

  ```ts
  // Access the CommitId of a GitHub source in the synth
  const source = pipelines.CodePipelineSource.gitHub('owner/repo', 'main');

  const pipeline = new pipelines.CodePipeline(scope, 'MyPipeline', {
    synth: new pipelines.ShellStep('Synth', {
      input: source,
      commands: [],
      env: {
        'COMMIT_ID': source.sourceAttribute('CommitId'),
      }
    })
  });
  ```

- `toString(): string` — Return a string representation of this Step.
