简体   繁体   English

部署前使用AWS CodeBuild或Lambda运行茉莉花测试

[英]Using AWS CodeBuild or Lambda to run jasmine tests before deployment

Folks, Have been trying to figure out the correct way to fire of a CodeBuild project which either produces the artifact after compiling and running jasmine tests, or fails and stops the CodePipeline from proceeding with deployment. 民间人士,一直在尝试找出CodeBuild项目的正确启动方式,该项目要么在编译和运行茉莉花测试后生成工件,要么失败并阻止CodePipeline继续进行部署。

If my buildspec.yml looks like: 如果我的buildspec.yml看起来像:

version: 0.1

phases:
  install:
    commands:
      - echo Installing... Running npm install
      - npm install
  pre_build:
    commands:
      - echo pre_build...
  build:
    commands:
      - echo Testing... Running npm test
      - npm test
  post_build:
    commands:
      - echo Build completed on `date`
artifacts:
  files:
    - '**/*'

How should I fail out of the npm test phase? 我应该如何退出npm test阶段? If any of the jasmine tests fail during npm test , will the artifact still be produced? 如果在npm test期间任何茉莉花测试失败,是否还会产生伪影?

Another thought I have is to have the following occur if any of the tests fail: 我的另一种想法是,如果任何测试失败,则会发生以下情况:

    var params = {
        jobId: jobId,
        failureDetails: {
            message: JSON.stringify(message),
            type: 'JobFailed',
            externalExecutionId: context.invokeid
        }
    };
    codepipeline.putJobFailureResult(params, function(err, data) {
        ...
    });

or send a stop signal to CodeBuild? 或向CodeBuild发送停止信号?

var params = {
  id: 'STRING_VALUE' /* required */
};
codebuild.stopBuild(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

Or how do I terminate the build to not produce the artifact? 或如何终止构建以不产生构件? Maybe I got this wrong, and it should be a Lambda function that kicks off the unit tests. 也许我弄错了,应该是启动单元测试的Lambda函数。 I am not sure if Lambda is ideal for this, as I can imagine some services take a while to finish the unit tests 我不确定Lambda是否适合此操作,因为我可以想象某些服务需要一段时间才能完成单元测试

Thanks! 谢谢!

In case anyone stumbles upon this, both ways will work. 万一有人偶然发现,这两种方法都可以。 AWS CodeBuild will fail on any non-zero exit status code. AWS CodeBuild的任何非零退出状态代码都会失败。 Thus, any tests that fail will cause the pipeline to fail. 因此,任何失败的测试都将导致管道失败。

Same can be done with lambda lambda也可以做到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM