# ShellStep

Run shell script commands in the pipeline.

This is a generic step designed
to be deployment engine agnostic.

Extends: [Step](/cdk/api/v2/docs/aws-cdk-lib.pipelines.Step.html) › ShellStep
Implements: [IFileSetProducer](/cdk/api/v2/docs/aws-cdk-lib.pipelines.IFileSetProducer.html)
Superclass of: [CodeBuildStep](/cdk/api/v2/docs/aws-cdk-lib.pipelines.CodeBuildStep.html)

- Source: [`pipelines/lib/blueprint/shell-step.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/pipelines/lib/blueprint/shell-step.ts#L99)
- Type last changed: v2.60.0 · 12 Jan 2023

## Example

TypeScript:

```ts
declare const pipeline: pipelines.CodePipeline;
const preprod = new MyApplicationStage(this, 'PreProd');
const prod = new MyApplicationStage(this, 'Prod');
const topic = new sns.Topic(this, 'ChangeApprovalTopic');

pipeline.addStage(preprod, {
  post: [
    new pipelines.ShellStep('Validate Endpoint', {
      commands: ['curl -Ssf https://my.webservice.com/'],
    }),
  ],
});
pipeline.addStage(prod, {
  pre: [new pipelines.ManualApprovalStep('PromoteToProd', {
    //All options below are optional
    comment: 'Please validate changes',
    reviewUrl: 'https://my.webservice.com/',
    notificationTopic: topic,
  })],
});
```

Python:

```python
# pipeline: pipelines.CodePipeline

preprod = MyApplicationStage(self, "PreProd")
prod = MyApplicationStage(self, "Prod")
topic = sns.Topic(self, "ChangeApprovalTopic")

pipeline.add_stage(preprod,
    post=[
        pipelines.ShellStep("Validate Endpoint",
            commands=["curl -Ssf https://my.webservice.com/"]
        )
    ]
)
pipeline.add_stage(prod,
    pre=[pipelines.ManualApprovalStep("PromoteToProd",
        # All options below are optional
        comment="Please validate changes",
        review_url="https://my.webservice.com/",
        notification_topic=topic
    )]
)
```

Java:

```java
CodePipeline pipeline;

MyApplicationStage preprod = new MyApplicationStage(this, "PreProd");
MyApplicationStage prod = new MyApplicationStage(this, "Prod");
Topic topic = new Topic(this, "ChangeApprovalTopic");

pipeline.addStage(preprod, AddStageOpts.builder()
        .post(List.of(
            ShellStep.Builder.create("Validate Endpoint")
                    .commands(List.of("curl -Ssf https://my.webservice.com/"))
                    .build()))
        .build());
pipeline.addStage(prod, AddStageOpts.builder()
        .pre(List.of(ManualApprovalStep.Builder.create("PromoteToProd")
                //All options below are optional
                .comment("Please validate changes")
                .reviewUrl("https://my.webservice.com/")
                .notificationTopic(topic)
                .build()))
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
CodePipeline pipeline;

var preprod = new MyApplicationStage(this, "PreProd");
var prod = new MyApplicationStage(this, "Prod");
var topic = new Topic(this, "ChangeApprovalTopic");

pipeline.AddStage(preprod, new AddStageOpts {
    Post = new [] {
        new ShellStep("Validate Endpoint", new ShellStepProps {
            Commands = new [] { "curl -Ssf https://my.webservice.com/" }
        }) }
});
pipeline.AddStage(prod, new AddStageOpts {
    Pre = new [] { new ManualApprovalStep("PromoteToProd", new ManualApprovalStepProps {
        //All options below are optional
        Comment = "Please validate changes",
        ReviewUrl = "https://my.webservice.com/",
        NotificationTopic = topic
    }) }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var pipeline CodePipeline

preprod := newMyApplicationStage(this, jsii.String("PreProd"))
prod := newMyApplicationStage(this, jsii.String("Prod"))
topic := sns.NewTopic(this, jsii.String("ChangeApprovalTopic"))

pipeline.AddStage(preprod, &AddStageOpts{
	Post: []Step{
		pipelines.NewShellStep(jsii.String("Validate Endpoint"), &ShellStepProps{
			Commands: []*string{
				jsii.String("curl -Ssf https://my.webservice.com/"),
			},
		}),
	},
})
pipeline.AddStage(prod, &AddStageOpts{
	Pre: []Step{
		pipelines.NewManualApprovalStep(jsii.String("PromoteToProd"), &ManualApprovalStepProps{
			//All options below are optional
			Comment: jsii.String("Please validate changes"),
			ReviewUrl: jsii.String("https://my.webservice.com/"),
			NotificationTopic: topic,
		}),
	},
})
```

## Initializer

TypeScript:

```ts
new ShellStep(id: string, props: ShellStepProps)
```

Python:

```python
ShellStep(id: str, props: ShellStepProps)
```

Java:

```java
new ShellStep(String id, ShellStepProps props)
```

C# / .NET:

```csharp
new ShellStep(string id, ShellStepProps props)
```

Golang:

```go
NewShellStep(Id *string, Props ShellStepProps)
```

## Properties

- `commands`: string[] — Commands to run.

- `consumedStackOutputs`: [StackOutputReference](/cdk/api/v2/docs/aws-cdk-lib.pipelines.StackOutputReference.html)[] — StackOutputReferences this step consumes.

- `dependencies`: [Step](/cdk/api/v2/docs/aws-cdk-lib.pipelines.Step.html)[] — Return the steps this step depends on, based on the FileSets it requires.

- `dependencyFileSets`: [FileSet](/cdk/api/v2/docs/aws-cdk-lib.pipelines.FileSet.html)[] — The list of FileSets consumed by this Step.

- `env`: { [key: string]: string } — Environment variables to set.

  **Default:** No environment variables

- `envFromCfnOutputs`: { [key: string]: [StackOutputReference](/cdk/api/v2/docs/aws-cdk-lib.pipelines.StackOutputReference.html) } — Set environment variables based on Stack Outputs.

  **Default:** No environment variables created from stack outputs

- `id`: string — Identifier for this step.

- `inputs`: [FileSetLocation](/cdk/api/v2/docs/aws-cdk-lib.pipelines.FileSetLocation.html)[] — Input FileSets.

  A list of `(FileSet, directory)` pairs, which are a copy of the
  input properties. This list should not be modified directly.

- `installCommands`: string[] — Installation commands to run before the regular commands.

  **Default:** No installation commands

  For deployment engines that support it, install commands will be classified
  differently in the job history from the regular `commands`.

- `isSource`: boolean — Whether or not this is a Source step.

  What it means to be a Source step depends on the engine.

- `outputs`: [FileSetLocation](/cdk/api/v2/docs/aws-cdk-lib.pipelines.FileSetLocation.html)[] — Output FileSets.

  A list of `(FileSet, directory)` pairs, which are a copy of the
  input properties. This list should not be modified directly.

- `primaryOutput`: [FileSet](/cdk/api/v2/docs/aws-cdk-lib.pipelines.FileSet.html) — The primary FileSet produced by this Step.

  Not all steps produce an output FileSet--if they do
  you can substitute the `Step` object for the `FileSet` object.

## Methods

- `addOutputDirectory(directory: string): FileSet` — Add an additional output FileSet based on a directory.

  After running the script, the contents of the given directory
  will be exported as a `FileSet`. Use the `FileSet` as the
  input to another step.

  Multiple calls with the exact same directory name string (not normalized)
  will return the same FileSet.

- `addStepDependency(step: Step): void` — Add a dependency on another step.

- `primaryOutputDirectory(directory: string): FileSet` — Configure the given output directory as primary output.

  If no primary output has been configured yet, this directory
  will become the primary output of this ShellStep, otherwise this
  method will throw if the given directory is different than the
  currently configured primary output directory.

- `sequence(steps: Step[]): Step[]` (static) — Define a sequence of steps to be executed in order.

  If you need more fine-grained step ordering, use the `addStepDependency()`
  API. For example, if you want `secondStep` to occur after `firstStep`, call
  `secondStep.addStepDependency(firstStep)`.

- `toString(): string` — Return a string representation of this Step.
