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
asked 2 years ago3951 views
2 Answers
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
EXPERT
Greg_B
answered 2 years ago
  • 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
answered 2 years ago
  • 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.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions