# RuleProps

Properties for defining a CodePipeline Rule.

Used as props by: [Rule](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline.Rule.html)

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

## Example

TypeScript:

```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'
            },
          })],
        }],
      },
    },
  ],

});
```

Python:

```python
# source_action: codepipeline_actions.CodeStarConnectionsSourceAction
# build_action: codepipeline_actions.CodeBuildAction

codepipeline.Pipeline(self, "Pipeline",
    pipeline_type=codepipeline.PipelineType.V2,
    stages=[codepipeline.StageProps(
        stage_name="Source",
        actions=[source_action]
    ), codepipeline.StageProps(
        stage_name="Build",
        actions=[build_action],
        # BeforeEntry condition - checks before entering the stage
        before_entry=codepipeline.Conditions(
            conditions=[codepipeline.Condition(
                rules=[codepipeline.Rule(
                    name="LambdaCheck",
                    provider="LambdaInvoke",
                    version="1",
                    configuration={
                        "FunctionName": "LambdaFunctionName"
                    }
                )],
                result=codepipeline.Result.FAIL
            )]
        ),
        # OnSuccess condition - checks after successful stage completion
        on_success=codepipeline.Conditions(
            conditions=[codepipeline.Condition(
                result=codepipeline.Result.FAIL,
                rules=[codepipeline.Rule(
                    name="CloudWatchCheck",
                    provider="LambdaInvoke",
                    version="1",
                    configuration={
                        "AlarmName": "AlarmName1",
                        "WaitTime": "300",  # 5 minutes
                        "FunctionName": "funcName2"
                    }
                )]
            )]
        ),
        # OnFailure condition - handles stage failure
        on_failure=codepipeline.FailureConditions(
            conditions=[codepipeline.Condition(
                result=codepipeline.Result.ROLLBACK,
                rules=[codepipeline.Rule(
                    name="RollBackOnFailure",
                    provider="LambdaInvoke",
                    version="1",
                    configuration={
                        "AlarmName": "Alarm",
                        "WaitTime": "300",  # 5 minutes
                        "FunctionName": "funcName1"
                    }
                )]
            )]
        )
    )
    ]
)
```

Java:

```java
CodeStarConnectionsSourceAction sourceAction;
CodeBuildAction buildAction;

Pipeline.Builder.create(this, "Pipeline")
        .pipelineType(PipelineType.V2)
        .stages(List.of(StageProps.builder()
                .stageName("Source")
                .actions(List.of(sourceAction))
                .build(), StageProps.builder()
                .stageName("Build")
                .actions(List.of(buildAction))
                // BeforeEntry condition - checks before entering the stage
                .beforeEntry(Conditions.builder()
                        .conditions(List.of(Condition.builder()
                                .rules(List.of(Rule.Builder.create()
                                        .name("LambdaCheck")
                                        .provider("LambdaInvoke")
                                        .version("1")
                                        .configuration(Map.of(
                                                "FunctionName", "LambdaFunctionName"))
                                        .build()))
                                .result(Result.FAIL)
                                .build()))
                        .build())
                // OnSuccess condition - checks after successful stage completion
                .onSuccess(Conditions.builder()
                        .conditions(List.of(Condition.builder()
                                .result(Result.FAIL)
                                .rules(List.of(Rule.Builder.create()
                                        .name("CloudWatchCheck")
                                        .provider("LambdaInvoke")
                                        .version("1")
                                        .configuration(Map.of(
                                                "AlarmName", "AlarmName1",
                                                "WaitTime", "300",  // 5 minutes
                                                "FunctionName", "funcName2"))
                                        .build()))
                                .build()))
                        .build())
                // OnFailure condition - handles stage failure
                .onFailure(FailureConditions.builder()
                        .conditions(List.of(Condition.builder()
                                .result(Result.ROLLBACK)
                                .rules(List.of(Rule.Builder.create()
                                        .name("RollBackOnFailure")
                                        .provider("LambdaInvoke")
                                        .version("1")
                                        .configuration(Map.of(
                                                "AlarmName", "Alarm",
                                                "WaitTime", "300",  // 5 minutes
                                                "FunctionName", "funcName1"))
                                        .build()))
                                .build()))
                        .build())
                .build()))
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
CodeStarConnectionsSourceAction sourceAction;
CodeBuildAction buildAction;

new Pipeline(this, "Pipeline", new PipelineProps {
    PipelineType = PipelineType.V2,
    Stages = new [] { new StageProps {
        StageName = "Source",
        Actions = new [] { sourceAction }
    }, new StageProps {
        StageName = "Build",
        Actions = new [] { buildAction },
        // BeforeEntry condition - checks before entering the stage
        BeforeEntry = new Conditions {
            Conditions = new [] { new Condition {
                Rules = new [] { new Rule(new RuleProps {
                    Name = "LambdaCheck",
                    Provider = "LambdaInvoke",
                    Version = "1",
                    Configuration = new Dictionary<string, string> {
                        { "FunctionName", "LambdaFunctionName" }
                    }
                }) },
                Result = Result.FAIL
            } }
        },
        // OnSuccess condition - checks after successful stage completion
        OnSuccess = new Conditions {
            Conditions = new [] { new Condition {
                Result = Result.FAIL,
                Rules = new [] { new Rule(new RuleProps {
                    Name = "CloudWatchCheck",
                    Provider = "LambdaInvoke",
                    Version = "1",
                    Configuration = new Dictionary<string, string> {
                        { "AlarmName", "AlarmName1" },
                        { "WaitTime", "300" },  // 5 minutes
                        { "FunctionName", "funcName2" }
                    }
                }) }
            } }
        },
        // OnFailure condition - handles stage failure
        OnFailure = new FailureConditions {
            Conditions = new [] { new Condition {
                Result = Result.ROLLBACK,
                Rules = new [] { new Rule(new RuleProps {
                    Name = "RollBackOnFailure",
                    Provider = "LambdaInvoke",
                    Version = "1",
                    Configuration = new Dictionary<string, string> {
                        { "AlarmName", "Alarm" },
                        { "WaitTime", "300" },  // 5 minutes
                        { "FunctionName", "funcName1" }
                    }
                }) }
            } }
        }
    } }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var sourceAction CodeStarConnectionsSourceAction
var buildAction CodeBuildAction

codepipeline.NewPipeline(this, jsii.String("Pipeline"), &PipelineProps{
	PipelineType: codepipeline.PipelineType_V2,
	Stages: []StageProps{
		&StageProps{
			StageName: jsii.String("Source"),
			Actions: []IAction{
				sourceAction,
			},
		},
		&StageProps{
			StageName: jsii.String("Build"),
			Actions: []IAction{
				buildAction,
			},
			// BeforeEntry condition - checks before entering the stage
			BeforeEntry: &Conditions{
				Conditions: []Condition{
					&Condition{
						Rules: []Rule{
							codepipeline.NewRule(&RuleProps{
								Name: jsii.String("LambdaCheck"),
								Provider: jsii.String("LambdaInvoke"),
								Version: jsii.String("1"),
								Configuration: map[string]*string{
									"FunctionName": jsii.String("LambdaFunctionName"),
								},
							}),
						},
						Result: codepipeline.Result_FAIL,
					},
				},
			},
			// OnSuccess condition - checks after successful stage completion
			OnSuccess: &Conditions{
				Conditions: []Condition{
					&Condition{
						Result: codepipeline.Result_FAIL,
						Rules: []Rule{
							codepipeline.NewRule(&RuleProps{
								Name: jsii.String("CloudWatchCheck"),
								Provider: jsii.String("LambdaInvoke"),
								Version: jsii.String("1"),
								Configuration: map[string]*string{
									"AlarmName": jsii.String("AlarmName1"),
									"WaitTime": jsii.String("300"),
									 // 5 minutes
									"FunctionName": jsii.String("funcName2"),
								},
							}),
						},
					},
				},
			},
			// OnFailure condition - handles stage failure
			OnFailure: &FailureConditions{
				Conditions: []Condition{
					&Condition{
						Result: codepipeline.Result_ROLLBACK,
						Rules: []Rule{
							codepipeline.NewRule(&RuleProps{
								Name: jsii.String("RollBackOnFailure"),
								Provider: jsii.String("LambdaInvoke"),
								Version: jsii.String("1"),
								Configuration: map[string]*string{
									"AlarmName": jsii.String("Alarm"),
									"WaitTime": jsii.String("300"),
									 // 5 minutes
									"FunctionName": jsii.String("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](https://docs.aws.amazon.com/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.
