4

我正在使用 Typescript 中的 aws-cdk v0.31.0 开发 AWS CodePipeline。

尝试合成 cloudformation 模板时出现验证错误

throw new Error(`Validation failed with the following errors:\n  ${errorList}`);
          ^
Error: Validation failed with the following errors:
  [SummitCodePipelineDemoStack/Pipeline] Artifact 'compile-output' was used as input before being used as output
at Synthesizer.synthesize (/home/stefan/Private/programmieren/aws/cdk/SummitCodePipelineDemo/node_modules/@aws-cdk/cdk/lib/synthesis.ts:51:15)
at App.run (/home/stefan/Private/programmieren/aws/cdk/SummitCodePipelineDemo/node_modules/@aws-cdk/cdk/lib/app.ts:75:27)
at Object.<anonymous> (/home/stefan/Private/programmieren/aws/cdk/SummitCodePipelineDemo/bin/summit_code_pipeline_demo.ts:8:5)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:283:19)
Subprocess exited with error 1

根据错误消息,我在将工件用作输出之前将其用作输入 - 不确定我是如何做到的。下面我提供了我的代码

export class SummitCodePipelineDemoStack extends Stack {
  codeRepository: Repository;
  imageDefinitionArtifact: Artifact = new Artifact("imagedefinition_json");

  constructor(scope: App, id: string, props?: StackProps) {
    super(scope, id, props);
    const sourceOutput = new Artifact();
    const compileOutput = new Artifact("compile-output");

    this.codeRepository = this.createCodeCommitRepository();

    new Pipeline(this, "Pipeline", {
      pipelineName: "ThymeLeadDemoBuildPipeline",
      stages: [
        {
          name: "Stage1",
          actions: [this.SourceAction(sourceOutput)]
        },
        {
          name: "Stage2",
          actions: [
            this.BuildAction(sourceOutput, compileOutput),
            this.ContainerAction(compileOutput)
          ]
        }
      ]
    });
      }

  private createCodeCommitRepository(): Repository {
    return new Repository(this, "CodeCommitRepository", {
  repositoryName: "thymeleafdemorepository",
  description: "Spring Boot Demo with Thymeleaf."
    });
  }

  private SourceAction(output: Artifact): Action {
    return new CodeCommitSourceAction({
  repository: this.codeRepository,
  actionName: "SourceAction",
  output
    });
  }

  private ContainerAction(input: Artifact): Action {
    return new CodeBuildAction({
      actionName: "CreationOfContainer",
      project: new PipelineProject(
        this,
        "MyContainerCreationProject",
        this.createProjectProperties()
      ),
      input
    });
  }

  private BuildAction(input: Artifact, output: Artifact): Action {
    return new CodeBuildAction({
      actionName: "CompileCode",
      project: new PipelineProject(this, "CompileProject", {
        projectName: "ThymeLeafDemoCompile",
        environment: {
          buildImage: LinuxBuildImage.UBUNTU_14_04_OPEN_JDK_11
        }
      }),
      input,
      output
    });
  }

  private createProjectProperties(): PipelineProjectProps {
    return {
      projectName: "thymeleafdemocontainerproject",
      environment: {
        buildImage: LinuxBuildImage.UBUNTU_14_04_DOCKER_17_09_0
      }
    };
  }
}
4

1 回答 1

1

我自己想出了答案:这似乎是 cdk 本身的一个错误,并且从这里的两三天开始跟踪 https://github.com/awslabs/aws-cdk/issues/2549

于 2019-05-18T04:39:37.293 回答