# VariableProps

Properties of pipeline-level variable.

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

- Source: [`aws-codepipeline/lib/variable.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-codepipeline/lib/variable.ts#L9)
- Type last changed: v2.128.0 · 14 Feb 2024

## Example

TypeScript:

```ts
declare const sourceAction: codepipeline_actions.S3SourceAction;
declare const sourceOutput: codepipeline.Artifact;
declare const deployBucket: s3.Bucket;

// Pipeline-level variable
const variable = new codepipeline.Variable({
  variableName: 'bucket-var',
  description: 'description',
  defaultValue: 'sample',
});

new codepipeline.Pipeline(this, 'Pipeline', {
  pipelineType: codepipeline.PipelineType.V2,
  variables: [variable],
  stages: [
    {
      stageName: 'Source',
      actions: [sourceAction],
    },
    {
      stageName: 'Deploy',
      actions: [
        new codepipeline_actions.S3DeployAction({
          actionName: 'DeployAction',
          // can reference the variables
          objectKey: `${variable.reference()}.txt`,
          input: sourceOutput,
          bucket: deployBucket,
        }),
      ],
    },
  ],
});
```

Python:

```python
# source_action: codepipeline_actions.S3SourceAction
# source_output: codepipeline.Artifact
# deploy_bucket: s3.Bucket

# Pipeline-level variable
variable = codepipeline.Variable(
    variable_name="bucket-var",
    description="description",
    default_value="sample"
)

codepipeline.Pipeline(self, "Pipeline",
    pipeline_type=codepipeline.PipelineType.V2,
    variables=[variable],
    stages=[codepipeline.StageProps(
        stage_name="Source",
        actions=[source_action]
    ), codepipeline.StageProps(
        stage_name="Deploy",
        actions=[
            codepipeline_actions.S3DeployAction(
                action_name="DeployAction",
                # can reference the variables
                object_key=f"{variable.reference()}.txt",
                input=source_output,
                bucket=deploy_bucket
            )
        ]
    )
    ]
)
```

Java:

```java
S3SourceAction sourceAction;
Artifact sourceOutput;
Bucket deployBucket;

// Pipeline-level variable
Variable variable = Variable.Builder.create()
        .variableName("bucket-var")
        .description("description")
        .defaultValue("sample")
        .build();

Pipeline.Builder.create(this, "Pipeline")
        .pipelineType(PipelineType.V2)
        .variables(List.of(variable))
        .stages(List.of(StageProps.builder()
                .stageName("Source")
                .actions(List.of(sourceAction))
                .build(), StageProps.builder()
                .stageName("Deploy")
                .actions(List.of(
                    S3DeployAction.Builder.create()
                            .actionName("DeployAction")
                            // can reference the variables
                            .objectKey(String.format("%s.txt", variable.reference()))
                            .input(sourceOutput)
                            .bucket(deployBucket)
                            .build()))
                .build()))
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
S3SourceAction sourceAction;
Artifact sourceOutput;
Bucket deployBucket;

// Pipeline-level variable
var variable = new Variable(new VariableProps {
    VariableName = "bucket-var",
    Description = "description",
    DefaultValue = "sample"
});

new Pipeline(this, "Pipeline", new PipelineProps {
    PipelineType = PipelineType.V2,
    Variables = new [] { variable },
    Stages = new [] { new StageProps {
        StageName = "Source",
        Actions = new [] { sourceAction }
    }, new StageProps {
        StageName = "Deploy",
        Actions = new [] {
            new S3DeployAction(new S3DeployActionProps {
                ActionName = "DeployAction",
                // can reference the variables
                ObjectKey = $"{variable.reference()}.txt",
                Input = sourceOutput,
                Bucket = deployBucket
            }) }
    } }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var sourceAction S3SourceAction
var sourceOutput Artifact
var deployBucket Bucket

// Pipeline-level variable
variable := codepipeline.NewVariable(&VariableProps{
	VariableName: jsii.String("bucket-var"),
	Description: jsii.String("description"),
	DefaultValue: jsii.String("sample"),
})

codepipeline.NewPipeline(this, jsii.String("Pipeline"), &PipelineProps{
	PipelineType: codepipeline.PipelineType_V2,
	Variables: []Variable{
		variable,
	},
	Stages: []StageProps{
		&StageProps{
			StageName: jsii.String("Source"),
			Actions: []IAction{
				sourceAction,
			},
		},
		&StageProps{
			StageName: jsii.String("Deploy"),
			Actions: []IAction{
				codepipeline_actions.NewS3DeployAction(&S3DeployActionProps{
					ActionName: jsii.String("DeployAction"),
					// can reference the variables
					ObjectKey: fmt.Sprintf("%v.txt", variable.Reference()),
					Input: sourceOutput,
					Bucket: deployBucket,
				}),
			},
		},
	},
})
```

## Properties

- `defaultValue`: string — The default value of a pipeline-level variable.

  **Default:** No default value.

- `description`: string — The description of a pipeline-level variable.

  **Default:** No description.

  It's used to add additional context
  about the variable, and not being used at time when pipeline executes.

- `variableName`: string (required) — The name of a pipeline-level variable.
