Created
February 5, 2020 01:04
-
-
Save richardhboyd/21e495c632a27f358168355b8577e969 to your computer and use it in GitHub Desktop.
Codepipeline Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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