mrjackdavis / grunt-msdeploy

GNU General Public License v2.0
3 stars 6 forks source link

A way to ignore errors? #3

Open PaulHuizer opened 10 years ago

PaulHuizer commented 10 years ago

I think i need a way to ignore errors. For example when using the runcommand to kill a running task. In case the dest task is not running, taskkill fails. I don't mind, I could ignore the error and the deployment process can simply continue.

For this reason I added ignoreErrors:true variable to the options object, like so:

options: {
                    verb: "sync",
                    source: "runCommand",
                    dest: {
                        runCommand: "taskkill /f /im " + FullAppName,
                        computername: "https://someserver/MsDeploy.axd",
                        username: "someUser",
                        password: "somePassword",
                        authType: "basic"
                    },
                    allowUntrusted: true,
                    ignoreErrors : true,
                }

In msdeploy.js I made the following modifications:

        delete options["msdeployPath"];

        var ignoreErrors = options.ignoreErrors;
        if (ignoreErrors != undefined)
            delete options["ignoreErrors"];

        for (var key in options) {

and

            if (!stderr && stderr !== "") {
                if (ignoreErrors) {
                    grunt.log.writeln("stderr:\"" + stderr + "\"");
                    grunt.log.writeln("ignoreErrors:true => continue..");
                } else {
                    grunt.fail.warn("stderr:\"" + stderr + "\"", 3);
                }
            }
            if (error !== null) {
                if (ignoreErrors) {
                    grunt.log.writeln(error);
                    grunt.log.writeln("ignoreErrors:true => continue..");
                }
                else {
                    grunt.fail.warn(error, 3);
                }
            }

For me it works very nice. Mayb I've overlooked some obvious alternative, I hope you can merge it in the package. thanx in advance.

mrjackdavis commented 10 years ago

Hi PaulHuizer, Looks okay. I've never used runcommand to kill a running task, so I'm unsure about your use case. The only time -force hasn't worked for me is when I want one task to pass if it errors as opposed to all. The only case I've come across is running tests and returning the test results even if they failed for an integration server.

Feel free to open a pull request with your changes, I'll review them there.

If you could please further explain your use case so that I understand the need behind this, that'd be great.

PaulHuizer commented 10 years ago

I did not manage to get the --force option to work, maybe that would be a more obvious solution? Anyway, i looked further ... In the above case one task requires an 'ignoreerrors' flag, while the next task does require to stop the deploy process on an error. The situation I'm using this is on the test environment where I deploy some console apps... if they are running on the test server, then the consapps cannot be updated with new versions. So they have to be killed first. However, If they are not running anyway, in which case taskkill exits with an error, the next update process can proceed as planned. Hence the ignoreerrors flag on the taskkill.

If the --force would be an alternative, than this ignoreerrors is not needed. If --force is not an option for this use case, than i would love to see something like ignoreerros implemented. I'd be happy to make a pullrequest. Could you explain if and how --force could be an alternative solution?