'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. Now I want to create a Jenkins pipeline, Like in the first stage the first stack has been built and deployed,

now I want to use the first stack outputs as second stack's inputs and the same for the third and fouth folders.



Solution 1:[1]

To use another stack's output, use the 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 will figure out the necessary outputs/imports under the hood, and will deploy the stacks in the correct order automatically.

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)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1