Skip to content

Commit 8a100e5

Browse files
skinny85Elad Ben-Israel
authored and
Elad Ben-Israel
committed
feat(codepipeline): make Pipeline importable by ARN (#3469)
Add the capability to import an externally-defined CodePipeline using Pipeline.fromPipelineArn(). Fixes #3467
1 parent e15d391 commit 8a100e5

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

Diff for: packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ export interface PipelineProps {
103103
}
104104

105105
abstract class PipelineBase extends Resource implements IPipeline {
106-
public abstract pipelineName: string;
107-
public abstract pipelineArn: string;
106+
public abstract readonly pipelineName: string;
107+
public abstract readonly pipelineArn: string;
108108

109109
/**
110110
* Defines an event rule triggered by this CodePipeline.
@@ -159,6 +159,22 @@ abstract class PipelineBase extends Resource implements IPipeline {
159159
* // ... add more stages
160160
*/
161161
export class Pipeline extends PipelineBase {
162+
/**
163+
* Import a pipeline into this app.
164+
*
165+
* @param scope the scope into which to import this pipeline
166+
* @param id the logical ID of the returned pipeline construct
167+
* @param pipelineArn The ARN of the pipeline (e.g. `arn:aws:codepipeline:us-east-1:123456789012:MyDemoPipeline`)
168+
*/
169+
public static fromPipelineArn(scope: Construct, id: string, pipelineArn: string): IPipeline {
170+
class Import extends PipelineBase {
171+
public readonly pipelineName = Stack.of(scope).parseArn(pipelineArn).resource;
172+
public readonly pipelineArn = pipelineArn;
173+
}
174+
175+
return new Import(scope, id);
176+
}
177+
162178
/**
163179
* The IAM role AWS CodePipeline will use to perform actions or assume roles for actions with
164180
* a more specific IAM role.

Diff for: packages/@aws-cdk/aws-codepipeline/test/test.pipeline.ts

+12
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,17 @@ export = {
2828

2929
test.done();
3030
},
31+
32+
'can be imported by ARN'(test: Test) {
33+
const stack = new cdk.Stack();
34+
35+
const pipeline = codepipeline.Pipeline.fromPipelineArn(stack, 'Pipeline',
36+
'arn:aws:codepipeline:us-east-1:123456789012:MyPipeline');
37+
38+
test.equal(pipeline.pipelineArn, 'arn:aws:codepipeline:us-east-1:123456789012:MyPipeline');
39+
test.equal(pipeline.pipelineName, 'MyPipeline');
40+
41+
test.done();
42+
},
3143
},
3244
};

0 commit comments

Comments
 (0)