我正在嘗試擁有一個從 Github 獲取代碼并部署它的管道(Lambda、DynamoDB 等,使用 CDK)。我目前正在嘗試使其正常作業CodeStarConnectionsSourceAction,但我的代碼因此錯誤而失敗:
[Example4BePipeline/Example4BePipeline/Pipeline] Action Synth in stage Build: first stage may only contain Source actions
[Example4BePipeline/Example4BePipeline/Pipeline] Action 'Synth' is using input Artifact 'Sources', which is not being produced in this pipeline
我產生該錯誤的代碼是:
import * as cdk from "aws-cdk-lib"
import {Construct} from "constructs"
import {Example4BeDeployStage} from "./example4-be-deploy-stage"
import {CodeBuildStep, CodePipeline, CodePipelineFileSet} from "aws-cdk-lib/pipelines"
import {CodeStarConnectionsSourceAction} from "aws-cdk-lib/aws-codepipeline-actions";
import {Artifact} from "aws-cdk-lib/aws-codepipeline";
export class PipelineStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props)
const sourceOutput = new Artifact("Sources");
const sourceAction = new CodeStarConnectionsSourceAction({
actionName: "Github",
owner: "username",
repo: "example4-be",
output: sourceOutput,
connectionArn: "arn:aws:codestar-connections:us-east-1:....:connection/...."
})
const pipeline = new CodePipeline(this, "Example4BePipeline", {
pipelineName: "Example4BePipeline",
synth: new CodeBuildStep("Synth", {
input: CodePipelineFileSet.fromArtifact(sourceOutput),
installCommands: [
"npm install -g aws-cdk"
],
commands: [
"npm ci",
"npm run build",
"npx cdk synth"
]
}
),
selfMutation: false // TODO: remove before committing.
})
}
}
我在這里做錯了什么?
uj5u.com熱心網友回復:
我想通了,這是作業代碼,更短/簡潔:
import * as cdk from "aws-cdk-lib"
import {Construct} from "constructs"
import {Example4BeDeployStage} from "./example4-be-deploy-stage"
import {CodeBuildStep, CodePipeline, CodePipelineSource} from "aws-cdk-lib/pipelines"
export class PipelineStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props)
const pipeline = new CodePipeline(this, "Example4BePipeline", {
pipelineName: "Example4BePipeline",
synth: new CodeBuildStep("Synth", {
input: CodePipelineSource.connection("username/example4-be", "main", {
connectionArn: "arn:aws:codestar-connections:us-east-1:....:connection/....",
}),
installCommands: [
"npm install -g aws-cdk"
],
commands: [
"npm ci",
"npm run build",
"npx cdk synth"
]
}
),
selfMutation: false // TODO: remove before committing.
})
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/409342.html
標籤:
