# nodeSh

This step runs a shell script in a Node.js prepared Docker container. The step also ensures access to our private GitHub npm registry by providing the value of the `GITHUB_NPM_TOKEN` to the container.

## Parameters

| Name        | Description                       | Type     | Default | Required                            |
| ----------- | --------------------------------- | -------- | ------- | ----------------------------------- |
| script      | The script to run                 | `String` | n/a     | yes                                 |
| nodeVersion | The node version to use.          | `String` | n/a     | yes, if no `.nvmrc` file in project |
| envVars     | Map of environment variables.     | `Map`    | null    | no                                  |
| user        | The user running the Docker image | `String` | 'node'  | no                                  |

## Usage

Unless you specify the `nodeVersion`, the version is automatically picked up by your project `.nvmrc` file.

**Note that you have to specify a supported Node.js version.**

#### The currently supported versions are:

- **18**
- **20.11.1**
- **20**
- **20-build**
- **22**
- **24**

### Using `.nvmrc`

If your `.nvmrc` file contains, e.g., `20.11.1`, then the following example will run the script in a Docker container using the [docker-parent-images:node20.11.1](https://github.com/theorchard/docker-parent-images/tree/master/node20.11.1) image.

```groovy
nodeSh(
    script: 'echo hi'
)

```

### Shorthand notation

The step supports calling it with a single string like the `sh` step.

```groovy
nodeSh 'echo hi'
```

### With specified node version

If you do not have a `.nvmrc` file or you want to override it, you can specify the version using the `nodeVersion` param.

```groovy
nodeSh(script: 'echo hi', nodeVersion: '20.11.1')
```

### Providing environment variables

Use the `envVars` parameter to provide environment variables to the docker container.

```groovy
nodeSh(
    script: 'echo hi',
    envVars: [
        MY_ENV_VAR: '1234'
    ]
)
```

### Adding supported node versions

To add a new node version, you need to do the following:

- Create a PR in the [docker-parent-images](https://github.com/theorchard/docker-parent-images) repo, pinning the new version. [Example PR](https://github.com/theorchard/docker-parent-images/pull/65)
- Create a PR in this repo, updating the `SUPPORTED_NODE_VERSIONS` array and this readme with the new version.
