From 543aa3831aa6c8c8f8a8e7650ab7eb541eeff085 Mon Sep 17 00:00:00 2001 From: Maciej Skierkowski Date: Mon, 6 Jan 2020 15:40:24 -0800 Subject: [PATCH] docs: Adding note on using serverless-plugin-scripts --- docs/dashboard/cicd/custom-scripts.md | 83 +++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 5 deletions(-) diff --git a/docs/dashboard/cicd/custom-scripts.md b/docs/dashboard/cicd/custom-scripts.md index 4685c1c39..a96f31e50 100644 --- a/docs/dashboard/cicd/custom-scripts.md +++ b/docs/dashboard/cicd/custom-scripts.md @@ -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': '' }, } ``` -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': '' }, +} +``` + +**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': '' }, +} +``` + +**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': '' }, +} +``` + +**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': +``` + +**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’: +``` + +## 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.