Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Codepipeline Example
import * as cc from '@aws-cdk/aws-codecommit';
import * as cb from '@aws-cdk/aws-codebuild';
import * as cp from '@aws-cdk/aws-codepipeline';
import * as cpActions from '@aws-cdk/aws-codepipeline-actions';
import * as cdk from '@aws-cdk/core';
export class PipelineVariablesStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const repo = new cc.Repository(this, "myRepo", {
repositoryName: "RichardsRepository"
});
const pipeline = new cp.Pipeline(this, "MyPipeline")
const sourceArtifact = new cp.Artifact("SourceArtifact");
const buildArtifact = new cp.Artifact("BuildArtifact");
const project = new cb.Project(this, "MyBuildProject", {
environment: {
buildImage: cb.LinuxBuildImage.STANDARD_2_0,
computeType: cb.ComputeType.LARGE,
environmentVariables: {"foo": {value: "bar"}}
},
buildSpec: cb.BuildSpec.fromObject({
"version": 0.2,
"phases": {
"build": {
"commands":[
"touch source1_file",
"cd $CODEBUILD_SRC_DIR_source2",
"touch source2_file"
]
}
},
"artifacts": {
"secondary-artifacts": {
"artifact1": {
"base-directory": "$CODEBUILD_SRC_DIR",
"files": ["source1_file"]
},
"artifact2":{
"base-directory": "$CODEBUILD_SRC_DIR_source2",
"files": ["source2_file"]
}
}
}
})
});
const consumeProject = new cb.Project(this, "MyConsumeBuildProject", {
environment: {
buildImage: cb.LinuxBuildImage.STANDARD_2_0,
computeType: cb.ComputeType.LARGE,
environmentVariables: {"foo": {value: "bar"}}
},
buildSpec: cb.BuildSpec.fromObject({
"version": 0.2,
"phases": {
"build": {
"commands":[
"touch source1_file",
"cd $CODEBUILD_SRC_DIR_source2",
"touch source2_file"
]
}
}
})
});
pipeline.addStage({
stageName: "SourceStage",
actions: [new cpActions.CodeCommitSourceAction({
actionName: "CodeCommitSource",
output: sourceArtifact,
repository: repo
})],
});
pipeline.addStage({
stageName: "BuildStage",
actions: [new cpActions.CodeBuildAction({
actionName: "BuildAction",
input: sourceArtifact,
outputs: [buildArtifact],
project: project,
variablesNamespace: "myCodeBuildNameSpace"
})]
});
pipeline.addStage({
stageName: "ConsumeBuildStage",
actions: [new cpActions.CodeBuildAction({
actionName: "ConsumeBuildAction",
input: buildArtifact,
project: project,
variablesNamespace: "myCodeBuildNameSpace"
})]
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment