1. Answers
  2. Changing AWS CodeBuild Project Environment Variables

How do I change AWS CodeBuild project environment variables?

In this guide, we will demonstrate how to change environment variables for an AWS CodeBuild project using Pulumi. AWS CodeBuild is a fully managed continuous integration service that compiles source code, runs tests, and produces software packages. Environment variables are key-value pairs that provide runtime configuration for your builds.

Below is a Pulumi program written in TypeScript that modifies the environment variables of an existing AWS CodeBuild project.

import * as aws from "@pulumi/aws";

// Define a new CodeBuild project or import an existing one
const codeBuildProject = new aws.codebuild.Project("myCodeBuildProject", {
    name: "myCodeBuildProject",
    source: {
        type: "GITHUB",
        location: "https://github.com/my/repo",
    },
    artifacts: {
        type: "NO_ARTIFACTS",
    },
    environment: {
        computeType: "BUILD_GENERAL1_SMALL",
        image: "aws/codebuild/standard:4.0",
        type: "LINUX_CONTAINER",
        environmentVariables: [
            {
                name: "ENV_VAR_1",
                value: "new_value_1",
            },
            {
                name: "ENV_VAR_2",
                value: "new_value_2",
            },
        ],
    },
    serviceRole: "arn:aws:iam::123456789012:role/service-role/codebuild-service-role",
});

Key Points:

  • We use the aws.codebuild.Project resource to define or import an existing CodeBuild project.
  • The environment block specifies the environment variables using the environmentVariables property.
  • Each environment variable is defined with a name and value.

Summary:

We have shown how to modify environment variables for an AWS CodeBuild project using Pulumi. By defining the environmentVariables property within the environment block of the aws.codebuild.Project resource, we can easily manage and update the environment variables required for our build processes.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up