mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
docs: Adding note on using serverless-plugin-scripts
This commit is contained in:
parent
5bfabffcd7
commit
543aa3831a
@ -13,18 +13,91 @@ layout: Doc
|
||||
|
||||
# Custom scripts
|
||||
|
||||
Custom scripts in the pipeline are supported using the standard `scripts` in the `package.json` file.
|
||||
|
||||
For example, you can run scripts before/after install, and before/after a test.
|
||||
Serverless Framework Pro runs three primary operations on your repository when you have CI/CD configured: (1) install NPM packages via `npm install`, (2) run tests, if present, with `npm test`, and (3) deploy your service using `sls deploy`. You can run custom scripts before or after each of these steps if you need to customize the pipeline further.
|
||||
|
||||
To run custom scripts before & after NPM install and running tests, use the lifecycle hooks built into `scripts` of your `package.json` file. The `preinstall`, `postinstall`, `pretest`, and `posttest`, scripts are run automatically at each of these steps.
|
||||
|
||||
To run custom scripts before or after deployment, you can use the [serverless-plugin-scripts](https://github.com/mvila/serverless-plugin-scripts) plugin to run the scripts at various points of the `serverless deploy` lifecycle, including before deployment and on finalize.
|
||||
|
||||
**Before npm install**
|
||||
|
||||
To run a script before `npm install`, set the script in `preinstall` in your `package.json`.
|
||||
|
||||
```yaml
|
||||
{
|
||||
'name': 'demo-serverless',
|
||||
'version': '1.0.0',
|
||||
'scripts': { 'preinstall': '', 'postinstall': '', 'pretest': '', 'posttest': '' },
|
||||
'scripts': { 'preinstall': '<your script>' },
|
||||
}
|
||||
```
|
||||
|
||||
Additional lifecycle hooks can be found in the `npm` documentation:
|
||||
|
||||
[https://docs.npmjs.com/misc/scripts](https://docs.npmjs.com/misc/scripts)
|
||||
**After npm install**
|
||||
|
||||
To run a script after `npm install`, set the script in `postinstall` in your `package.json`.
|
||||
|
||||
```yaml
|
||||
{
|
||||
'name': 'demo-serverless',
|
||||
'version': '1.0.0',
|
||||
'scripts': { 'postinstall': '<your script>' },
|
||||
}
|
||||
```
|
||||
|
||||
**Before npm test**
|
||||
|
||||
To run a script before `npm test`, set the script in `pretest` in your `package.json`.
|
||||
|
||||
```yaml
|
||||
{
|
||||
'name': 'demo-serverless',
|
||||
'version': '1.0.0',
|
||||
'scripts': { 'pretest': '<your script>' },
|
||||
}
|
||||
```
|
||||
|
||||
**After npm test**
|
||||
|
||||
To run a script after `npm test`, set the script in `posttest` in your `package.json`.
|
||||
|
||||
```yaml
|
||||
{
|
||||
'name': 'demo-serverless',
|
||||
'version': '1.0.0',
|
||||
'scripts': { 'posttest': '<your script>' },
|
||||
}
|
||||
```
|
||||
|
||||
**Before serverless deploy**
|
||||
|
||||
To run a script before `serverless deploy` starts the deployment add this to your `serverless.yml`.
|
||||
|
||||
```yaml
|
||||
plugins:
|
||||
- serverless-plugin-scripts
|
||||
custom:
|
||||
scripts:
|
||||
hooks:
|
||||
‘before:deploy:deploy': <your script>
|
||||
```
|
||||
|
||||
**After serverless deploy**
|
||||
|
||||
To run a script after `serverless deploy` completes a deployment add this to your `serverless.yml`.
|
||||
|
||||
```yaml
|
||||
plugins:
|
||||
- serverless-plugin-scripts
|
||||
custom:
|
||||
scripts:
|
||||
hooks:
|
||||
‘deploy:finalize’: <your script>
|
||||
```
|
||||
|
||||
## Additional lifecycle hooks
|
||||
|
||||
NPM provide additional lifecycle hooks you can run as well, additional documentation can be found here, [https://docs.npmjs.com/misc/scripts](https://docs.npmjs.com/misc/scripts).
|
||||
|
||||
|
||||
Serverless Framework provides additional lifecycle hooks as “serverless deploy” is running, you can find more information about additional hooks in the [serverless-plugin-scripts](https://github.com/mvila/serverless-plugin-scripts) docs.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user