weixu365 / serverless-scriptable-plugin

Adding script support to Serverless 1.x which enables you to customize Serverless behavior without writing a plugin.
MIT License
111 stars 11 forks source link

Exit code #53

Closed joelvh closed 4 years ago

joelvh commented 4 years ago

I love using this plugin. I've found that when I specify a build script to run when deploying my serverless service, if the build script fails, the serverless framework doesn't seem to emit an error code. This causes the CI job to report a success instead of failure.

Have you seen this issue before and do you know if it's a setting in the serverless framework, or in this plugin?

Thanks!

weixu365 commented 4 years ago

I could not reproduce the problem, could you please add more details? e.g. serverless.yml content, the script that fails to run and also serverless version.

Here are my testing results.

Test executing a bash file serverless.yml file

custom:
  scriptHooks:
    after:package:compileEvents: ./cmd.sh

cmd.sh file

echo Building serverless app
grep a test

Output:

$ npx serverless package
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Running command: ./cmd.sh
Building serverless app
grep: test: No such file or directory

  Error --------------------------------------------------

  Error: Command failed: ./cmd.sh

Test executing a nodejs script

serverless.yml

custom:
  scriptHooks:
    after:package:compileEvents: test.js

test.js

console.log("test in script");

println('hello')
// throw 1 // or any other errors

Output:

$ npx serverless package
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Running javascript file: test.js
test in script

  Reference Error ----------------------------------------

  test.js:3
println('hello')
^

ReferenceError: println is not defined
    at test.js:3:1
weixu365 commented 4 years ago

Any update on this issue @joelvh ?

joelvh commented 4 years ago

@weixu365 I found this issue that might be related, but unclear if it's supposedly resolve. The issue is not closed, so it could still be the cause. https://github.com/serverless/serverless/issues/6441

What do you think? Is there something related to this that the Scriptable plugin might do differently to get an exception raised?

weixu365 commented 4 years ago

I still don't understand what's the issue. Could you please add more details about the issue like what I did above, so I'll know if it's related to this plugin or not?

It fails with exit code 1 on my machine if the script fails.

serverless.yml

custom:
  scriptHooks:
    before:package:createDeploymentArtifacts: npm run build

package.json

  "scripts": {
    "build": "grep a test"
  }

Output:

$ npx serverless package
Running command: npm run build

> docker@1.0.0 build /Users/wxu/projects/serverless-scriptable-plugin/examples/docker
> grep a test

grep: test: No such file or directory
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! docker@1.0.0 build: `grep a test`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the docker@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
...

$ echo $?
1
joelvh commented 4 years ago

Hi @weixu365, one script runs a Webpack build script. The other uses one of the Serverless plugins to update the domain on the service. The deployment was run using GitHub Actions, and even though the log (below) shows that there was an error, the GitHub Action did not fail. That means we didn't know that it failed and had to re-run the deployment after fixing the bug.

The other issue I linked to in my previous comment suggest that maybe the Serverless Offline plugin has something to do with it. Although, I just noticed I'm not using that plugin on this service (but I am using for others). So, maybe it's something similar we're dealing with on the Scriptable plugin.

Serverless.yml

service: web-service
app: app
org: org

frameworkVersion: '>=1.63.0'

plugins:
  - serverless-webpack
  - serverless-finch
  - serverless-cloudfront-invalidate
  - serverless-plugin-reducer
  - serverless-scriptable-plugin

package:
  individually: true

provider:
  name: aws
  runtime: nodejs12.x
  stage: ${opt:stage}
  region: us-east-1
  memorySize: 512
  timeout: 30
  tracing:
    apiGateway: true
    lambda: true
  environment: ${file(../../serverless-environment.yml):${self:service}.${self:provider.stage}}

custom:
  platform: web
  # local values for resolving config
  local:
    domainName: ''
    hostedZoneId: ''
    cfCertificateArn: ''
  dev:
    domainName: www.example.dev
    hostedZoneId: Z2000000000000
    cfCertificateArn: arn:aws:acm:us-east-1:000000000000:certificate/8a1256d4-0000-0000-bb96-fda83b4040de
  scriptHooks:
    after:deploy:finalize:
      - sls client deploy --no-confirm -v -s ${self:provider.stage}
    before:client:deploy:deploy:
      - SCHEMA_ENV=${self:provider.environment.SCHEMA_ENV} STAGE=${self:provider.stage} npm run build
    after:client:deploy:deploy:
      - sls cloudfrontInvalidate -v -s ${self:provider.stage}
  webpack:
    webpackConfig: 'webpack.config.cjs'
    packager: 'npm'
    includeModules: false
    # excludeFiles:
  cloudfrontInvalidate:
    # Output key
    distributionIdKey: ClientDistributionId
    items:
      - /
      - /index.html
  client:
    manageResources: false
    bucketName: origin-${self:service}-${self:provider.stage}
    distributionFolder: ./build/
    objectHeaders:
      '*.html':
        - name: Cache-Control
          value: no-cache

Package.json

{
  "scripts": {
    "build": "webpack --config ./webpack.config.babel.js --progress false --display-error-details --bail --trace-deprecation",
    "deploy": "sls deploy --no-confirm -v -s $STAGE"
  },
  "devDependencies": {
    "serverless-cloudfront-invalidate": "^1.3.0",
    "serverless-domain-manager": "^3.3.1",
    "serverless-finch": "^2.4.2",
    "serverless-plugin-reducer": "^3.2.3",
    "serverless-scriptable-plugin": "^1.0.5",
    "serverless-webpack": "^5.3",
    "webpack": "^4.42.1"
  }
}

GitHub Actions Log

2020-04-10T06:02:50.6540554Z Deploying stack...
2020-04-10T06:02:50.6540818Z 
2020-04-10T06:02:54.4335125Z Serverless: Using configuration:
2020-04-10T06:02:54.4336117Z {
2020-04-10T06:02:54.4336502Z   "webpackConfig": "webpack.config.cjs",
2020-04-10T06:02:54.4336851Z   "packager": "npm",
2020-04-10T06:02:54.4337169Z   "includeModules": false,
2020-04-10T06:02:54.4337468Z   "packagerOptions": {},
2020-04-10T06:02:54.4337788Z   "keepOutputDirectory": false
2020-04-10T06:02:54.4338089Z }
2020-04-10T06:02:54.4344679Z Serverless: Removing /home/runner/work/repo/packages/web/.webpack
2020-04-10T06:02:54.4349304Z Serverless: Using multi-compile (individual packaging)
2020-04-10T06:02:54.4359963Z Serverless: Bundling with Webpack...
2020-04-10T06:02:54.9941955Z Serverless: Packaging service...
2020-04-10T06:02:54.9949339Z Serverless: Remove /home/runner/work/repo/packages/web/.webpack
2020-04-10T06:02:55.5767932Z Serverless: Uploading CloudFormation file to S3...
2020-04-10T06:02:55.6796882Z Serverless: Uploading artifacts...
2020-04-10T06:02:55.6806085Z Serverless: Validating template...
2020-04-10T06:02:55.9844140Z Serverless: Updating Stack...
2020-04-10T06:02:56.4560974Z Service Information
2020-04-10T06:02:56.4562809Z service: web-service
2020-04-10T06:02:56.4563240Z stage: dev
2020-04-10T06:02:56.4563779Z region: us-east-1
2020-04-10T06:02:56.4564678Z stack: web-service-dev
2020-04-10T06:02:56.4565047Z resources: 7
2020-04-10T06:02:56.4565432Z api keys:
2020-04-10T06:02:56.4565746Z   None
2020-04-10T06:02:56.4566049Z endpoints:
2020-04-10T06:02:56.4566347Z   None
2020-04-10T06:02:56.4566681Z functions:
2020-04-10T06:02:56.4566978Z   None
2020-04-10T06:02:56.4567286Z layers:
2020-04-10T06:02:56.4567587Z   None
2020-04-10T06:02:56.4570157Z 
2020-04-10T06:02:56.4570536Z Stack Outputs
2020-04-10T06:02:56.4570992Z ClientDistributionDomainName: d3000000000000.cloudfront.net
2020-04-10T06:02:56.4571434Z CustomDomainNameEndpoint: https://www.example.dev
2020-04-10T06:02:56.4572406Z ServerlessDeploymentBucketName: web-service-dev-serverlessdeploymentbucket
2020-04-10T06:02:56.4573062Z ClientDistributionId: E3000000000000
2020-04-10T06:02:56.4573500Z 
2020-04-10T06:02:57.0075875Z DistributionIdKey: ClientDistributionId
2020-04-10T06:02:57.0235311Z Failed to get DistributionId from stack output. Please check your serverless template.
2020-04-10T06:02:57.0711338Z Serverless: Removing old service artifacts from S3...
2020-04-10T06:02:57.3319194Z Serverless: Publishing service to the Serverless Dashboard...
2020-04-10T06:02:58.1925594Z Serverless: Successfully published your service to the Serverless Dashboard: https://dashboard.serverless.com/tenants/org/applications/app/services/web-service/stage/dev/region/us-east-1
2020-04-10T06:02:58.1942151Z Running command: sls client deploy --no-confirm -v -s dev
2020-04-10T06:03:01.8519405Z Running command: SCHEMA_ENV=dev STAGE=dev npm run build
2020-04-10T06:03:02.0752825Z 
2020-04-10T06:03:02.0754516Z > web-service@1.0.0 build /home/runner/work/repo/packages/web
2020-04-10T06:03:02.0755616Z > cd ../.. && PLATFORM=web npm run ui:build
2020-04-10T06:03:02.0755978Z 
2020-04-10T06:03:02.2916754Z 
2020-04-10T06:03:02.2918313Z > repo@1.0.0 ui:build /home/runner/work/repo
2020-04-10T06:03:02.2918956Z > eval "$(scripts/serverless-print-dotenv)" && cd packages/ui && NODE_ENV=production npm run build
2020-04-10T06:03:02.2919049Z 
2020-04-10T06:03:06.3640433Z 
2020-04-10T06:03:06.3642498Z > repo@0.4.0 build /home/runner/work/repo/packages/ui
2020-04-10T06:03:06.3643747Z > webpack --config ./webpack.config.babel.js --progress false --display-error-details --bail --trace-deprecation
2020-04-10T06:03:06.3644232Z 
2020-04-10T06:03:10.6611159Z /home/runner/work/repo/packages/ui/node_modules/webpack-cli/bin/cli.js:93
2020-04-10T06:03:10.6611908Z                throw err;
2020-04-10T06:03:10.6612159Z                ^
2020-04-10T06:03:10.6612327Z 
2020-04-10T06:03:10.6612586Z ReferenceError: window is not defined
2020-04-10T06:03:10.6613232Z     at createWriter (/home/runner/work/repo/packages/ui/src/lib/logger.js:4:20)
2020-04-10T06:03:10.6613851Z     at createLogger (/home/runner/work/repo/packages/ui/src/lib/logger.js:24:12)
2020-04-10T06:03:10.6615249Z     at Object.<anonymous> (/home/runner/work/repo/packages/ui/src/lib/logger.js:33:16)
2020-04-10T06:03:10.6616131Z     at Module._compile (/home/runner/work/repo/packages/ui/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
2020-04-10T06:03:10.6616764Z     at Module._compile (/home/runner/work/repo/packages/ui/node_modules/pirates/lib/index.js:99:24)
2020-04-10T06:03:10.6617659Z     at Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
2020-04-10T06:03:10.6618441Z     at Object.newLoader [as .js] (/home/runner/work/repo/packages/ui/node_modules/pirates/lib/index.js:104:7)
2020-04-10T06:03:10.6618818Z     at Module.load (internal/modules/cjs/loader.js:1000:32)
2020-04-10T06:03:10.6619141Z     at Function.Module._load (internal/modules/cjs/loader.js:899:14)
2020-04-10T06:03:10.6619782Z     at Module.require (internal/modules/cjs/loader.js:1042:19)
2020-04-10T06:03:10.6620546Z     at require (/home/runner/work/repo/packages/ui/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
2020-04-10T06:03:10.6621750Z     at Object.<anonymous> (/home/runner/work/repo/packages/ui/webpack.config.babel.js:22:1)
2020-04-10T06:03:10.6622686Z     at Module._compile (/home/runner/work/repo/packages/ui/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
2020-04-10T06:03:10.6623390Z     at Module._compile (/home/runner/work/repo/packages/ui/node_modules/pirates/lib/index.js:99:24)
2020-04-10T06:03:10.6623767Z     at Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
2020-04-10T06:03:10.6624453Z     at Object.newLoader [as .js] (/home/runner/work/repo/packages/ui/node_modules/pirates/lib/index.js:104:7)
2020-04-10T06:03:10.6624819Z     at Module.load (internal/modules/cjs/loader.js:1000:32)
2020-04-10T06:03:10.6625112Z     at Function.Module._load (internal/modules/cjs/loader.js:899:14)
2020-04-10T06:03:10.6625420Z     at Module.require (internal/modules/cjs/loader.js:1042:19)
2020-04-10T06:03:10.6626139Z     at require (/home/runner/work/repo/packages/ui/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
2020-04-10T06:03:10.6627290Z     at WEBPACK_OPTIONS (/home/runner/work/repo/packages/ui/node_modules/webpack-cli/bin/utils/convert-argv.js:114:13)
2020-04-10T06:03:10.6628762Z     at requireConfig (/home/runner/work/repo/packages/ui/node_modules/webpack-cli/bin/utils/convert-argv.js:116:6)
2020-04-10T06:03:10.6630019Z     at /home/runner/work/repo/packages/ui/node_modules/webpack-cli/bin/utils/convert-argv.js:123:17
2020-04-10T06:03:10.6630682Z     at Array.forEach (<anonymous>)
2020-04-10T06:03:10.6631471Z     at module.exports (/home/runner/work/repo/packages/ui/node_modules/webpack-cli/bin/utils/convert-argv.js:121:15)
2020-04-10T06:03:10.6632060Z     at /home/runner/work/repo/packages/ui/node_modules/webpack-cli/bin/cli.js:71:45
2020-04-10T06:03:10.6633252Z     at Object.parse (/home/runner/work/repo/packages/ui/node_modules/webpack-cli/node_modules/yargs/yargs.js:567:18)
2020-04-10T06:03:10.6634081Z     at /home/runner/work/repo/packages/ui/node_modules/webpack-cli/bin/cli.js:49:8
2020-04-10T06:03:10.6636753Z     at Object.<anonymous> (/home/runner/work/repo/packages/ui/node_modules/webpack-cli/bin/cli.js:366:3)
2020-04-10T06:03:10.6638096Z     at Module._compile (internal/modules/cjs/loader.js:1156:30)
2020-04-10T06:03:10.6638482Z     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
2020-04-10T06:03:10.6638812Z     at Module.load (internal/modules/cjs/loader.js:1000:32)
2020-04-10T06:03:10.6639130Z     at Function.Module._load (internal/modules/cjs/loader.js:899:14)
2020-04-10T06:03:10.6639442Z     at Module.require (internal/modules/cjs/loader.js:1042:19)
2020-04-10T06:03:10.6639740Z     at require (internal/modules/cjs/helpers.js:77:18)
2020-04-10T06:03:10.6641155Z     at Object.<anonymous> (/home/runner/work/repo/packages/ui/node_modules/webpack/bin/webpack.js:156:2)
2020-04-10T06:03:10.6912860Z npm ERR! code ELIFECYCLE
2020-04-10T06:03:10.6913428Z npm ERR! errno 1
2020-04-10T06:03:10.6921411Z npm ERR! repo@0.4.0 build: `webpack --config ./webpack.config.babel.js --progress false --display-error-details --bail --trace-deprecation`
2020-04-10T06:03:10.6921991Z npm ERR! Exit status 1
2020-04-10T06:03:10.6922338Z npm ERR! 
2020-04-10T06:03:10.6922966Z npm ERR! Failed at the repo@0.4.0 build script.
2020-04-10T06:03:10.6923725Z npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-04-10T06:03:10.7118542Z 
2020-04-10T06:03:10.7119542Z npm ERR! A complete log of this run can be found in:
2020-04-10T06:03:10.7121905Z npm ERR!     /home/runner/.npm/_logs/2020-04-10T06_03_10_692Z-debug.log
2020-04-10T06:03:10.7183983Z npm ERR! code ELIFECYCLE
2020-04-10T06:03:10.7185853Z npm ERR! errno 1
2020-04-10T06:03:10.7194106Z npm ERR! repo@1.0.0 ui:build: `eval "$(scripts/serverless-print-dotenv)" && cd packages/ui && NODE_ENV=production npm run build`
2020-04-10T06:03:10.7194592Z npm ERR! Exit status 1
2020-04-10T06:03:10.7196155Z npm ERR! 
2020-04-10T06:03:10.7197382Z npm ERR! Failed at the repo@1.0.0 ui:build script.
2020-04-10T06:03:10.7198136Z npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-04-10T06:03:10.7236230Z npm WARN Local package.json exists, but node_modules missing, did you mean to install?
2020-04-10T06:03:10.7240515Z 
2020-04-10T06:03:10.7243633Z npm ERR! A complete log of this run can be found in:
2020-04-10T06:03:10.7245639Z npm ERR!     /home/runner/.npm/_logs/2020-04-10T06_03_10_720Z-debug.log
2020-04-10T06:03:10.7463205Z npm ERR! code ELIFECYCLE
2020-04-10T06:03:10.7463597Z npm ERR! errno 1
2020-04-10T06:03:10.7464264Z npm ERR! web-service@1.0.0 build: `cd ../.. && PLATFORM=web npm run ui:build`
2020-04-10T06:03:10.7464459Z npm ERR! Exit status 1
2020-04-10T06:03:10.7464592Z npm ERR! 
2020-04-10T06:03:10.7464973Z npm ERR! Failed at the web-service@1.0.0 build script.
2020-04-10T06:03:10.7465267Z npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-04-10T06:03:10.7531826Z 
2020-04-10T06:03:10.7534576Z npm ERR! A complete log of this run can be found in:
2020-04-10T06:03:10.7537445Z npm ERR!     /home/runner/.npm/_logs/2020-04-10T06_03_10_743Z-debug.log
2020-04-10T06:03:10.7596992Z  
2020-04-10T06:03:10.7600884Z   Error --------------------------------------------------
2020-04-10T06:03:10.7601498Z  
2020-04-10T06:03:10.7603021Z   Error: Command failed: SCHEMA_ENV=dev STAGE=dev npm run build
2020-04-10T06:03:10.7603510Z       at checkExecSyncError (child_process.js:630:11)
2020-04-10T06:03:10.7603733Z       at execSync (child_process.js:666:15)
2020-04-10T06:03:10.7604462Z       at Scriptable.runCommand (/home/runner/work/repo/packages/web/node_modules/serverless-scriptable-plugin/index.js:48:12)
2020-04-10T06:03:10.7605038Z       at /home/runner/work/repo/packages/web/node_modules/serverless-scriptable-plugin/index.js:41:21
2020-04-10T06:03:10.7605533Z       at tryCatcher (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/util.js:16:23)
2020-04-10T06:03:10.7606055Z       at Object.gotValue (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/reduce.js:166:18)
2020-04-10T06:03:10.7606564Z       at Object.gotAccum (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/reduce.js:155:25)
2020-04-10T06:03:10.7607072Z       at Object.tryCatcher (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/util.js:16:23)
2020-04-10T06:03:10.7607608Z       at Promise._settlePromiseFromHandler (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/promise.js:547:31)
2020-04-10T06:03:10.7608106Z       at Promise._settlePromise (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/promise.js:604:18)
2020-04-10T06:03:10.7608628Z       at Promise._settlePromiseCtx (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/promise.js:641:10)
2020-04-10T06:03:10.7609131Z       at _drainQueueStep (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/async.js:97:12)
2020-04-10T06:03:10.7609898Z       at _drainQueue (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/async.js:86:9)
2020-04-10T06:03:10.7610409Z       at Async._drainQueues (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/async.js:102:5)
2020-04-10T06:03:10.7611023Z       at Immediate.Async.drainQueues [as _onImmediate] (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/async.js:15:14)
2020-04-10T06:03:10.7611222Z       at processImmediate (internal/timers.js:456:21)
2020-04-10T06:03:10.7611397Z       at process.topLevelDomainCallback (domain.js:137:15)
2020-04-10T06:03:10.7611519Z  
2020-04-10T06:03:10.7614382Z      For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
2020-04-10T06:03:10.7614803Z  
2020-04-10T06:03:10.7617136Z   Get Support --------------------------------------------
2020-04-10T06:03:10.7618861Z      Docs:          docs.serverless.com
2020-04-10T06:03:10.7621206Z      Bugs:          github.com/serverless/serverless/issues
2020-04-10T06:03:10.7623605Z      Issues:        forum.serverless.com
2020-04-10T06:03:10.7625013Z  
2020-04-10T06:03:10.7627506Z   Your Environment Information ---------------------------
2020-04-10T06:03:10.7630840Z      Operating System:          linux
2020-04-10T06:03:10.7632648Z      Node Version:              12.16.2
2020-04-10T06:03:10.7634262Z      Framework Version:         1.67.3
2020-04-10T06:03:10.7636204Z      Plugin Version:            3.6.6
2020-04-10T06:03:10.7637127Z      SDK Version:               2.3.0
2020-04-10T06:03:10.7639358Z      Components Version:        2.29.1
2020-04-10T06:03:10.7640190Z  
2020-04-10T06:03:10.8046393Z Serverless: Publishing service to the Serverless Dashboard...
2020-04-10T06:03:11.7023100Z Serverless: Successfully published your service to the Serverless Dashboard: https://dashboard.serverless.com/tenants/org/applications/app/services/web-service/stage/dev/region/us-east-1
2020-04-10T06:03:11.7028171Z  
2020-04-10T06:03:11.7029020Z   Error --------------------------------------------------
2020-04-10T06:03:11.7029221Z  
2020-04-10T06:03:11.7031457Z   Error: Command failed: sls client deploy --no-confirm -v -s dev
2020-04-10T06:03:11.7031805Z       at checkExecSyncError (child_process.js:630:11)
2020-04-10T06:03:11.7032034Z       at execSync (child_process.js:666:15)
2020-04-10T06:03:11.7032640Z       at Scriptable.runCommand (/home/runner/work/repo/packages/web/node_modules/serverless-scriptable-plugin/index.js:48:12)
2020-04-10T06:03:11.7033242Z       at /home/runner/work/repo/packages/web/node_modules/serverless-scriptable-plugin/index.js:41:21
2020-04-10T06:03:11.7034286Z       at tryCatcher (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/util.js:16:23)
2020-04-10T06:03:11.7035122Z       at Object.gotValue (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/reduce.js:166:18)
2020-04-10T06:03:11.7035778Z       at Object.gotAccum (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/reduce.js:155:25)
2020-04-10T06:03:11.7036362Z       at Object.tryCatcher (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/util.js:16:23)
2020-04-10T06:03:11.7037019Z       at Promise._settlePromiseFromHandler (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/promise.js:547:31)
2020-04-10T06:03:11.7037619Z       at Promise._settlePromise (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/promise.js:604:18)
2020-04-10T06:03:11.7038264Z       at Promise._settlePromiseCtx (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/promise.js:641:10)
2020-04-10T06:03:11.7038852Z       at _drainQueueStep (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/async.js:97:12)
2020-04-10T06:03:11.7040904Z       at _drainQueue (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/async.js:86:9)
2020-04-10T06:03:11.7041657Z       at Async._drainQueues (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/async.js:102:5)
2020-04-10T06:03:11.7042559Z       at Immediate.Async.drainQueues [as _onImmediate] (/home/runner/work/repo/packages/web/node_modules/bluebird/js/release/async.js:15:14)
2020-04-10T06:03:11.7042934Z       at processImmediate (internal/timers.js:456:21)
2020-04-10T06:03:11.7043388Z       at process.topLevelDomainCallback (domain.js:137:15)
2020-04-10T06:03:11.7043645Z  
2020-04-10T06:03:11.7043962Z      For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
2020-04-10T06:03:11.7044359Z  
2020-04-10T06:03:11.7044809Z   Get Support --------------------------------------------
2020-04-10T06:03:11.7045085Z      Docs:          docs.serverless.com
2020-04-10T06:03:11.7045537Z      Bugs:          github.com/serverless/serverless/issues
2020-04-10T06:03:11.7045756Z      Issues:        forum.serverless.com
2020-04-10T06:03:11.7045993Z  
2020-04-10T06:03:11.7046401Z   Your Environment Information ---------------------------
2020-04-10T06:03:11.7046693Z      Operating System:          linux
2020-04-10T06:03:11.7046951Z      Node Version:              12.16.2
2020-04-10T06:03:11.7047196Z      Framework Version:         1.67.3
2020-04-10T06:03:11.7047407Z      Plugin Version:            3.6.6
2020-04-10T06:03:11.7047659Z      SDK Version:               2.3.0
2020-04-10T06:03:11.7047871Z      Components Version:        2.29.1
2020-04-10T06:03:11.7048089Z  
2020-04-10T06:03:11.7156692Z 
weixu365 commented 4 years ago

There are a few places could causing the problem, so I would suggest you run it locally, and then check the exit code using echo $?

From the output above, serverless is failing, and based on what I tried before, serverless always return a non zero code if it failed. But could be an edge case that failed but still returned 0, in that case, it's easier to troubleshoot by running the command on your local.

If it still doesn't work, then maybe try to find out the root cause, e.g. disable all the plugins, and then enable one by one to find out the root cause, which could be one of:

joelvh commented 3 years ago

@weixu365 I finally discovered the issue. From what I've found, there are some cases where exit codes are ignored (get swallowed) because of how our bash scripts are set up. For example, we have a deploy script and inside of that, we have some scripts that setup the environment variables and then run the serverless deploy command.

What we discovered today is an error that was happening in the script that sets up the environment variables, but the deploy script didn't fail and continued on to try and run serverless deploy anyways. Setting set -e in the deploy script lead to two discoveries: 1) that flag will kill the parent script in most circumstances, and 2) we were using eval on a subshell that caused an error, but eval ignored the error and just evaled the output of the subshell.

So, eval exacerbated the issue for us, but that was discovered after we set -e and that seems to respect any errors thrown in our scriptable plugin setup.

This seems like a fairly obvious setting to have tried out, but I think the eval call swallowing the errors misdirected our attention.

weixu365 commented 3 years ago

Glad to hear you solved the issue, I think it's a good practice to add set -euo pipefail in any script to stop immediately if any error happens. It will save time on this kind of trouble shootings

 -e

Exit immediately if a command exits with a non-zero status.

pipefail

If set, the return value of a pipeline is the value of the last (rightmost) command to exit with a non-zero status, or zero if all commands in the pipeline exit successfully. This option is disabled by default.

-u 
Treat unset variables and parameters other than the special parameters ‘@’ or ‘*’ as an error when performing parameter expansion. An error message will be written to the standard error, and a non-interactive shell will exit.