Ignore error from the preivous build task in tasks.json

Viewed 668

I configured tasks.json to build and run the application.

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "make"
        },
        {
            "label": "close the file",
            "type": "shell",
            "command": "somecommand"
        },
        {
            "label": "Run build",
            "dependsOn": [
                "build",
                "close the file"
            ],
            "dependsOrder": "sequence",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

The flow is first make command will execute and after that somecommand will be executed. The problem is some times make command returns exit code other than zero, Because of that somecommand is not executing. Is there any way to ignore the previous build status and execute the somecommand always?

2 Answers

To ignore error code in task, simply add some nop command at the end using || operator. Valid for both bash and batch.

Like:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "make || echo 0"
        },
        {
            "label": "close the file",
            "type": "shell",
            "command": "somecommand"
        },
        {
            "label": "Run build",
            "dependsOn": [
                "build",
                "close the file"
            ],
            "dependsOrder": "sequence",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}
Related