class CodePipelineSource
Language | Type name |
---|---|
.NET | Amazon.CDK.Pipelines.CodePipelineSource |
Java | software.amazon.awscdk.pipelines.CodePipelineSource |
Python | aws_cdk.pipelines.CodePipelineSource |
TypeScript (source) | @aws-cdk/pipelines » CodePipelineSource |
Implements
IFile
, ICode
Extends
Step
Factory for CodePipeline source steps.
This class contains a number of factory methods for the different types of sources that CodePipeline supports.
Example
// 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
new CodePipelineSource(id: string)
Parameters
- id
string
— Identifier for this step.
Properties
Name | Type | Description |
---|---|---|
dependencies | Step [] | Return the steps this step depends on, based on the FileSets it requires. |
dependency | File [] | The list of FileSets consumed by this Step. |
id | string | Identifier for this step. |
is | boolean | Whether or not this is a Source step. |
primary | File | The primary FileSet produced by this Step. |
dependencies
Type:
Step
[]
Return the steps this step depends on, based on the FileSets it requires.
dependencyFileSets
Type:
File
[]
The list of FileSets consumed by this Step.
id
Type:
string
Identifier for this step.
isSource
Type:
boolean
Whether or not this is a Source step.
What it means to be a Source step depends on the engine.
primaryOutput?
Type:
File
(optional)
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
Name | Description |
---|---|
add | Add a dependency on another step. |
produce | Create the desired Action and add it to the pipeline. |
source | Return an attribute of the current source revision. |
to | Return a string representation of this Step. |
protected get | |
static code | Returns a CodeCommit source. |
static connection(repoString, branch, props) | Returns a CodeStar connection source. |
static ecr(repository, props?) | Returns an ECR source. |
static git | Returns a GitHub source, using OAuth tokens to authenticate with GitHub and a separate webhook to detect changes. |
static s3(bucket, objectKey, props?) | Returns an S3 source. |
StepDependency(step)
addpublic addStepDependency(step: Step): void
Parameters
- step
Step
Add a dependency on another step.
Action(stage, options)
producepublic produceAction(stage: IStage, options: ProduceActionOptions): CodePipelineActionFactoryResult
Parameters
- stage
IStage
- options
Produce
Action Options
Returns
Create the desired Action and add it to the pipeline.
Attribute(name)
sourcepublic sourceAttribute(name: string): string
Parameters
- name
string
Returns
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.
See also: https://docs.aws.amazon.com/codepipeline/latest/userguide/reference-variables.html#reference-variables-list Example
// 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'),
}
})
});
String()
topublic toString(): string
Returns
string
Return a string representation of this Step.
Action(output, actionName, runOrder, variablesNamespace?)
protected getprotected getAction(output: Artifact, actionName: string, runOrder: number, variablesNamespace?: string): Action
Parameters
- output
Artifact
- actionName
string
- runOrder
number
- variablesNamespace
string
Returns
Commit(repository, branch, props?)
static codepublic static codeCommit(repository: IRepository, branch: string, props?: CodeCommitSourceOptions): CodePipelineSource
Parameters
- repository
IRepository
— The CodeCommit repository. - branch
string
— The branch to use. - props
Code
— The source properties.Commit Source Options
Returns
Returns a CodeCommit source.
If you need access to symlinks or the repository history, be sure to set
codeBuildCloneOutput
.
Example
declare const repository: codecommit.IRepository;
pipelines.CodePipelineSource.codeCommit(repository, 'main');
static connection(repoString, branch, props)
public static connection(repoString: string, branch: string, props: ConnectionSourceOptions): CodePipelineSource
Parameters
- repoString
string
— A string that encodes owner and repository separated by a slash (e.g. 'owner/repo'). - branch
string
— The branch to use. - props
Connection
— The source properties, including the connection ARN.Source Options
Returns
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:
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
.
See also: https://docs.aws.amazon.com/dtconsole/latest/userguide/welcome-connections.html
static ecr(repository, props?)
public static ecr(repository: IRepository, props?: ECRSourceOptions): CodePipelineSource
Parameters
- repository
IRepository
— The repository that will be watched for changes. - props
ECRSource
— The options, which include the image tag to be checked for changes.Options
Returns
Returns an ECR source. Example
declare const repository: ecr.IRepository;
pipelines.CodePipelineSource.ecr(repository, {
imageTag: 'latest',
});
Hub(repoString, branch, props?)
static gitpublic static gitHub(repoString: string, branch: string, props?: GitHubSourceOptions): CodePipelineSource
Parameters
- repoString
string
- branch
string
- props
Git
Hub Source Options
Returns
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:
pipelines.CodePipelineSource.gitHub('owner/repo', 'main');
Authentication will be done by a secret called github-token
in AWS
Secrets Manager (unless specified otherwise).
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.
static s3(bucket, objectKey, props?)
public static s3(bucket: IBucket, objectKey: string, props?: S3SourceOptions): CodePipelineSource
Parameters
- bucket
IBucket
— The bucket where the source code is located. - objectKey
string
- props
S3
— The options, which include the key that identifies the source code file and and how the pipeline should be triggered.Source Options
Returns
Returns an S3 source. Example
declare const bucket: s3.Bucket;
pipelines.CodePipelineSource.s3(bucket, 'path/to/file.zip');