首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AWS管道python将工件传递到cdk.stage中的下一步

AWS管道python将工件传递到cdk.stage中的下一步
EN

Stack Overflow用户
提问于 2022-08-19 00:04:37
回答 1查看 251关注 0票数 0

我正在尝试使用python中的AWS创建一个AWS CodePipeline。

cdk子= 2.29.0

代码语言:javascript
复制
import aws_cdk as cdk
from aws_cdk.pipelines import CodePipeline, CodePipelineSource, ShellStep
from aws_cdk import (
    aws_codecommit,
    pipelines,
    aws_codepipeline_actions,
    aws_codepipeline,
    aws_codebuild as codebuild,
    aws_iam as iam
    )
from my_pipeline.my_pipeline_app_stage import MyPipelineAppStage
from constructs import Construct
        
        
class MyPipelineStack(cdk.Stack):

    def __init__(self, scope: Construct, construct_id: str, branch, **kwargs) -> None:
        super().__init__(scope, construct_id  ,**kwargs)
        
        
        repository = aws_codecommit.Repository.from_repository_name(self,"cdk_pipeline", repository_name="repository-name")
        
        pipeline_source = CodePipelineSource.code_commit(repository,"master")
        pipeline =  CodePipeline(self, "Pipeline",
                        self_mutation=False,
                        pipeline_name="cdk_pipeline",
                        synth=ShellStep("Synth", 
                            input=pipeline_source,
                            commands=["npm install -g aws-cdk", 
                                      "python -m pip install -r requirements.txt", 
                                    "cdk synth"],
                             
                        ),
                        
                        )

        shell_step1 = pipelines.ShellStep("Creating csv file", commands=["touch casa.csv"])
        shell_step2 = pipelines.ShellStep("Creating", commands=["touch cisa.csv"])
        shell_step3 = pipelines.ShellStep("printing", commands=["ls"])
        
        ordered_steps = pipelines.Step.sequence([shell_step1, shell_step2, shell_step3])
        
        
        app_stage = pipeline.add_stage(MyPipelineAppStage(self, "test",env=env_EU),
                                       pre=ordered_steps,
                                       )

我不知道如何将从shell_step1创建的输出传递给shell_step2和shell_step3。

如果我尝试将参数primary_output_directory添加到步骤shell中,如下所示:

代码语言:javascript
复制
pipeline =  CodePipeline(self, "Pipeline",
                        self_mutation=False,
                        pipeline_name="cdk_pipeline",
                        synth=ShellStep("Synth", 
                            input=pipeline_source,
                            commands=["npm install -g aws-cdk", 
                                      "python -m pip install -r requirements.txt", 
                                    "cdk synth"],
                             primary_output_directory = "cdk.out"
                        ),
                        
                        )

        shell_step1 = pipelines.ShellStep("Creating csv file", commands=["touch casa.csv"], primary_output_directory = "cdk.out")
        shell_step2 = pipelines.ShellStep("Creating", commands=["touch cisa.csv"], primary_output_directory = "cdk.out")
        shell_step3 = pipelines.ShellStep("printing", commands=["ls"], primary_output_directory = "cdk.out")
        
        ordered_steps = pipelines.Step.sequence([shell_step1, shell_step2, shell_step3])
        
        
        app_stage = pipeline.add_stage(MyPipelineAppStage(self, "test",env=env_EU),
                                       pre=ordered_steps,
                                       )

我知道这个错误

代码语言:javascript
复制
[Container] 2022/08/18 23:50:36 Phase context status code: CLIENT_ERROR Message: no matching base directory path found for cdk.out

我不知道是否有必要,我想我需要把人工制品从一个步骤传递到另一个步骤,但是我找不到该怎么做。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-19 13:39:05

若要将ShellStep的输出用作另一个ShellStep的输入,请将其直接传递到ShellStepinput支柱中。

代码语言:javascript
复制
shell_step_1 = pipelines.ShellStep("Creating csv file", input=pipeline_source, commands=["touch casa.csv"], primary_output_directory = "cdk.out")
shell_step_2 = pipelines.ShellStep("Creating", commands=["touch cisa.csv"], input=shell_step_1, primary_output_directory = ".")

shell_step_2将获取cdk.out的内容作为输入,因此它将不再有一个cdk.out文件夹。

这假设您的源代码包含一个cdk.out目录,这将不是常规的。如果要将synth步骤的输出传递给Shell步骤,则需要将其赋值给一个变量并将其作为输入传递:

代码语言:javascript
复制
synth_step = ShellStep(
    "Synth", 
    input=pipeline_source,
    commands=[
        "npm install -g aws-cdk", 
        "python -m pip install -r requirements.txt", 
        "cdk synth"
    ],   
)
shell_step_1 = pipelines.ShellStep(
    "Creating csv file",
    input=synth_step,
    commands=["touch casa.csv"],
    primary_output_directory="cdk.out"
)

但是,值得注意的是,单个shell步骤可以有多个shell命令--您不必为每个命令创建一个单独的命令。

参考资料:https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.pipelines.ShellStep.html#initializer

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73410601

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档