Promise改变了jenkins作业的exitCode,如何防止这种情况? [英] Promises change the exitCode of the jenkins job, how to prevent this?

查看:271
本文介绍了Promise改变了jenkins作业的exitCode,如何防止这种情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在protractor.conf文件中有以下记者:

I have the following reporters in the protractor.conf file:

 var promise1 = new Promise(function (resolve) {
    reporter1.afterLaunch(resolve.bind(this, exitCode));
});

var promise2 = new Promise(function (resolve) {
    reporter2.afterLaunch(resolve.bind(this, exitCode));
});

return Promise.all([promise1, promise2]);

上述每位记者都有他们自己的后期发布,预计会在发布后发布后执行.conf文件已执行。

Each of the above reporters have their own afterlaunch that would be expected to execute once the afterlaunch in the ptor.conf file is executed.

这是Jenkins中持续集成作业的一部分。所以正在发生的是,promise会解析,因此进程的退出代码变为0,即使测试失败因此也会覆盖作业的退出代码。因此即使它是一个合法的失败,詹金斯也将整个工作视为已经过去了。我需要保留传递给上述报告的 exitCode 的原始值,以使jenkins作业按预期运行。我们如何防止这种情况?

This is a part of the continuous integration job in Jenkins. So what's happening is that the promise resolves so the exit code of the process becomes 0, even when a test fails hence overwriting the exit code of the job. So even though its a legit failure the jenkins shows the entire job as PASSED. I need to preserve the original value of exitCode that is being passed to the above reports for the jenkins job to function as expected. How can we prevent this?

推荐答案

假设 exitCode Number resolve.bind(this,exitCode)返回一个函数,其第一个参数绑定到<$ c $的值c> exitCode 在声明这些变量(promise1和promise2)时

assuming exitCode is a Number the resolve.bind(this, exitCode) returns a function whose first parameter is bound to the value of exitCode at the time those vars (promise1 and promise2) are declared

所以在创建承诺之间对exitCode的任何更改当reporter1.afterLaunch回调被解雇时,将不会反映在承诺解决的价值中,

so any changes to exitCode between the time the promise is created and when the reporter1.afterLaunch callback gets fired will not be reflected in the value those promises resolve to,

ie假设在创建promises时exitCode为零,那么无论exitCode被更改为什么,解析后的值都将为零

i.e. assuming exitCode is zero when the promises are created, then the resolved value will be zero regardless of what exitCode is changed to

另一方面

var promise1 = new Promise(function (resolve) {
    reporter1.afterLaunch(() => resolve(exitCode));
});

var promise1 = new Promise(function (resolve) {
    reporter1.afterLaunch(function() {
        resolve(exitCode);
    });
});

将解析为exitCode的当前值

will resolve to the current value of exitCode

这篇关于Promise改变了jenkins作业的exitCode,如何防止这种情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆