# Variable

Pipeline-Level variable.

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

## Example

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

## Initializer

```ts
new Variable(props: VariableProps)
```

## Properties

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

## Methods

- `reference(): string` — Reference the variable name at Pipeline actions.

  **Returns:** The variable name in a format that can be referenced at Pipeline actions
