CodePipeline - how to pass and consume multiple artifacts across CodeBuild Steps?

0

Hello. I know I can pull multiple Source actions (e.g. 2 GitHub repos) into a CodeBuild step by adding multiple Source Artifacts. It would seem that i should follow the same pattern (e.g. $CODEBUILD_SRC_DIR__<secondary_artifact_name>) where individual CodeBuild actions are producing and consuming artifacts. In my case, my consuming step needs the following inputs:

  1. Source input (primary source, to get my buildspec.yml)
  2. The output of a prior CodeBuild step (a couple of files).

I am successful in setting up the Input/Output artifacts in my pipeline and validating that the zipped files are placed into the pipeline s3 bucket. Its all good up until that point.

However, when I run the consuming step and troll the file system I do not see anything like $CODEBUILD_SRC_DIR__<secondary_artifact_name>.

Is this scenario supported? if so, how do I reference the secondary artifacts in my CodeBuild buildspec?

Thanks Dave

DaveC
질문됨 2년 전4032회 조회
2개 답변
0

It is supported and the name you're looking for is correct. So I think you just have a small error.

Here's an example (CDK Typescript): https://github.com/awslabs/aws-greengrass-labs-component-for-the-things-stack-lorawan/blob/main/cicd/lib/cicd-stack.ts

The output from the build stage is passed as an extra input to the deploy stage. Both of which are CodeBuild actions:

        const buildAction = new codepipeline_actions.CodeBuildAction({
            actionName: `${Names.PREFIX_DASH}-build`,
            project: buildProject,
            input: source,
            outputs: [build]
        });

        const deployAction = new codepipeline_actions.CodeBuildAction({
            actionName: `${Names.PREFIX_DASH}-deploy`,
            project: deployProject,
            input: source,
            extraInputs: [build],
            outputs: [deploy],
            environmentVariables: {
                "GREENGRASS_CORE_NAME": { value: context.greengrassCoreName }
            }
        });

And the buildspec for the deploy stage, that consumes the output from the build stage: https://github.com/awslabs/aws-greengrass-labs-component-for-the-things-stack-lorawan/blob/main/cicd/deployspec.yaml

      # Get the recipe file generated by the build stage
      - RECIPE_FILE=$(ls $CODEBUILD_SRC_DIR_Build/aws.greengrass.labs.*.json)
profile pictureAWS
전문가
Greg_B
답변함 2년 전
  • Hey Greg - many apologies for not touching base back sooner. I saw your answer but was getting some weirdness in the portal. My scenario is specific to using CodeBuild within CodePipeline. There are some constraints with this that are not applicable with CodeBuild so I dont think this example will work for me.

  • Dave, the example above is indeed CodeBuild within CodePipeline.

0

How about caching in AWS CodeBuild. A cache can store reusable pieces of your build environment and use them across multiple builds. Your build project can use one of two types of caching: Amazon S3 or local.

CodeBuild also supports secondaryArtifacts. These artifacts use the secondary-artifacts block of the buildspec file that is nested inside the artifacts block.

RoB
답변함 2년 전
  • Hey RoB - thanks, I looked into caching and that appears to be an optimization for a single codebuild step - i need a normal workflow with separate producing and consuming steps. As for secondary artifacts, I'm using that feature - it just doesn't behave the way I would expect.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠