Promises change the exitCode of the jenkins job, how to prevent this?

巧了我就是萌 提交于 2019-12-08 12:24:49

问题


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]);

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.

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?


回答1:


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

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,

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

On the other hand

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

or

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

will resolve to the current value of exitCode



来源:https://stackoverflow.com/questions/41386162/promises-change-the-exitcode-of-the-jenkins-job-how-to-prevent-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!