简体   繁体   English

使用 jenkins 管道进行部署时,如何将参数从第一个 cdk 堆栈的 output 传递到另一个 cdk 堆栈的输入?

[英]How do i pass parameters from first cdk stack's output to another cdk stack's input, when deploying using jenkins pipeline?

I have one bitbucket repository, in that, I have 4 CDK stacks in a separate folder.我有一个 bitbucket 存储库,在那个存储库中,我在一个单独的文件夹中有 4 个 CDK 堆栈。 Now I want to create a Jenkins pipeline, Like in the first stage the first stack has been built and deployed,现在我想创建一个 Jenkins 管道,就像在第一阶段第一个堆栈已经构建和部署一样,

now I want to use the first stack outputs as second stack's inputs and the same for the third and fouth folders.现在我想将第一个堆栈输出用作第二个堆栈的输入,第三个和第四个文件夹也是如此。

To use another stack's output, use the Fn.importValue function .要使用另一个堆栈的 output,请使用Fn.importValue function

Like this:像这样:

imported_output = cdk.Fn.import_value("OUTPUT_NAME")

A good alternative would be to deploy all of your stacks together in a single CDK app and just pass the object references between your stacks.一个好的替代方案是将所有堆栈一起部署在一个 CDK 应用程序中,并在堆栈之间传递 object 引用。

CDK will figure out the necessary outputs/imports under the hood, and will deploy the stacks in the correct order automatically. CDK 将在后台计算出必要的输出/导入,并自动以正确的顺序部署堆栈。

Here's an example from the docs :这是文档中的示例:

prod = cdk.Environment(account="123456789012", region="us-east-1")

stack1 = StackThatProvidesABucket(app, "Stack1", env=prod)

# stack2 will take a property "bucket"
stack2 = StackThatExpectsABucket(app, "Stack2", bucket=stack1.bucket, env=prod)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM