Skip to content

Conversation

go-to-k
Copy link
Contributor

@go-to-k go-to-k commented Oct 14, 2025

Issue # (if applicable)

N/A

Reason for this change

CodePipeline supports the Environment Variables in actions, but L2 Pipeline with actions doesn't support it.

Description of changes

Added EnvironmentVariable with PlaintextEnvironmentVariable and SecretsManagerEnvironmentVariable.

Describe any new or updated permissions being added

Description of how you validated changes

Both unit tests and integ tests.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the p2 label Oct 14, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team October 14, 2025 14:16
@github-actions github-actions bot added the distinguished-contributor [Pilot] contributed 50+ PRs to the CDK label Oct 14, 2025
Comment on lines +363 to +368
/**
* The environment variables for the action.
*
* @default - no environment variables
*/
readonly actionEnvironmentVariables?: EnvironmentVariable[];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoided the name environmentVariables because CodeBuildActionProps that extends codepipeline.CommonAwsActionProps and this CommonActionProps has already used a property with the same name and an error occurs if the name is used in this props.

https://github.com/aws/aws-cdk/blob/v2.200.1/packages/aws-cdk-lib/aws-codepipeline-actions/lib/codebuild/build-action.ts#L81

Comment on lines +162 to +167
// Don't use `grantRead` method for the secret because `secretsmanager:DescribeSecret` is not required.
// See https://docs.aws.amazon.com/codepipeline/latest/userguide/action-reference-Commands.html#action-reference-Commands-envvars
options.role.addToPrincipalPolicy(new iam.PolicyStatement({
actions: ['secretsmanager:GetSecretValue'],
resources: [secretArn],
}));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.aws.amazon.com/codepipeline/latest/userguide/action-reference-Commands.html#action-reference-Commands-envvars

To use the SecretsManager, you must add the following permissions to your pipeline service role:

{
            "Effect": "Allow",
            "Action": [
                "secretsmanager:GetSecretValue"
            ],
            "Resource": [
                "SECRET_ARN"
            ]
        }

Comment on lines +85 to +89
/**
* Bind the environment variable to the action.
* @internal
*/
public abstract _bind(scope: Construct, actionProperties: ActionProperties, options: ActionBindOptions): void;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally, this abstract method was not made, but the concrete bind method was only created for SecretsManagerEnvironmentVariable. However, considering that support for PARAMETER_STORE may be added in the future, such as the one for CodeBuild, it is better to create the abstract method, so I did it this way. Otherwise, it would be necessary to implement the bind calling as follows. If more types are added in the future, the code will become even more complicated.

    envVars?.forEach(envVar => {
      if (envVar instanceof SecretsManagerEnvironmentVariable || envVar instanceof ParameterStoreEnvironmentVariable) {
        envVar._bind(scope, this.actionProperties, options);
      }
    });

Now we can write like:

    envVars?.forEach(envVar => {
      envVar._bind(scope, this.actionProperties, options);
    });

@go-to-k go-to-k changed the title feat(codepipeline): support environment variables for actions feat(codepipeline): support environment variables for action Oct 14, 2025
@go-to-k go-to-k changed the title feat(codepipeline): support environment variables for action feat(codepipeline): support environment variables for actions Oct 14, 2025
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

distinguished-contributor [Pilot] contributed 50+ PRs to the CDK p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants