# withBackoff – Retry Utility

The `withBackoff` step provides a flexible mechanism for retrying steps with configurable delay and backoff strategies.
It supports constant, linear, and exponential delay patterns and allows for a maximum delay cap.

## Parameters

| Name       | Description                                                                 | Type     | Default                 | Required |
|------------|-----------------------------------------------------------------------------|----------|-------------------------|----------|
| `strategy` | The delay strategy to use: `constant`, `linear`, or `exponential`.          | `String` | `"constant"`            | No       |
| `attempts` | Number of times to try executing the step. Must be ≥ 1.                     | `Integer`| `1`                     | No       |
| `delay`    | Base delay between retries (in seconds). Must be ≥ 0.                       | `Integer`| `0`                     | No       |
| `maxDelay` | Maximum delay allowed, regardless of strategy. Must be ≥ 0.                 | `Integer`| `Integer.MAX_VALUE`     | No       |
| `factor`   | Used only with the `exponential` strategy. Must be ≥ 1 if provided.         | `Integer`| `2`                     | No       |

## Strategies

- **constant**: Always delays for the same number of seconds (equal to `delay`).
- **linear**: Delay increases linearly with each attempt: `delay * (attempt + 1)`
- **exponential**: Delay increases exponentially with each attempt: `delay * (factor^attempt)`

## Example Usage

```groovy
withBackoff(
    strategy: 'exponential',
    attempts: 3,
    delay: 2,
    factor: 2,
    maxDelay: 10
) {
    sh 'some-flaky-command'
}
```

## Notes
* `factor` is only used with the `exponential` strategy and ignored otherwise.
* `maxDelay` is applied after computing the strategy-based delay.
* The body closure is retried only when it throws an exception.
