# RuleProps

Properties for defining a CodePipeline Rule.

Extends: RuleProps
Used as props by: Rule

- Source: [`aws-codepipeline/lib/rule.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-codepipeline/lib/rule.ts#L8)
- Type last changed: v2.186.0 · 27 Mar 2025

## Example

```ts
declare const sourceAction: codepipeline_actions.CodeStarConnectionsSourceAction;
declare const buildAction: codepipeline_actions.CodeBuildAction;

new codepipeline.Pipeline(this, 'Pipeline', {
  pipelineType: codepipeline.PipelineType.V2,
  stages: [
    {
      stageName: 'Source',
      actions: [sourceAction],
    },
    {
      stageName: 'Build',
      actions: [buildAction],
      // BeforeEntry condition - checks before entering the stage
      beforeEntry: {
        conditions: [{
          rules: [ new codepipeline.Rule({
            name: 'LambdaCheck',
            provider: 'LambdaInvoke',
            version: '1',
            configuration: {
              FunctionName: 'LambdaFunctionName',
            },
          })],
          result:  codepipeline.Result.FAIL,
        }],
      },
      // OnSuccess condition - checks after successful stage completion
      onSuccess: {
        conditions: [{
          result: codepipeline.Result.FAIL,
          rules: [new codepipeline.Rule({
            name: 'CloudWatchCheck',
            provider: 'LambdaInvoke',
            version: '1',
            configuration: {
              AlarmName: 'AlarmName1',
              WaitTime: '300', // 5 minutes
              FunctionName: 'funcName2'
            },
          })],
        }],
      },
      // OnFailure condition - handles stage failure
      onFailure: {
        conditions: [{
          result: codepipeline.Result.ROLLBACK,
            rules: [new codepipeline.Rule({
            name: 'RollBackOnFailure',
            provider: 'LambdaInvoke',
            version: '1',
            configuration: {
              AlarmName: 'Alarm',
              WaitTime: '300', // 5 minutes
              FunctionName: 'funcName1'
            },
          })],
        }],
      },
    },
  ],

});
```

## Properties

- `commands`: string[] — The shell commands to run with your commands rule in CodePipeline.

  **Default:** No commands

  All commands are supported except multi-line formats. While CodeBuild logs and permissions are used,
  you do not need to create any resources in CodeBuild.

- `configuration`: json — The action configuration fields for the rule.

  **Default:** No configuration

  This can include custom parameters specific to the rule type.

- `inputArtifacts`: string[] — The input artifacts fields for the rule, such as specifying an input file for the rule.

  **Default:** No input artifacts

  Each string in the array represents an artifact name that this rule will use as input.

- `name`: string — The name of the rule that is created for the condition.

  **Default:** A unique name will be generated

  Must be unique within the pipeline.

  ```ts
  'VariableCheck'
  ```

- `provider`: string — The rule provider that implements the rule's functionality.

  **Default:** No provider, must be specified if rule is used

  ```ts
  'DeploymentWindow'
  ```

- `region`: string — The AWS Region for the condition associated with the rule.

  **Default:** Pipeline's region

  If not specified, uses the pipeline's region.

- `role`: [Role](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.Role.html) — The IAM role that the rule will use to execute its actions.

  **Default:** A new role will be created

  The role must have sufficient permissions to perform the rule's tasks.

- `version`: string = '1' — The version of the rule to use.

  Different versions may have different features or behaviors.
