Ignore error from the preivous build task in tasks.json
Asked Answered
B

2

6

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?

Brunell answered 9/6, 2021 at 14:22 Comment(2)
write a shell script and run that with a taskToluidine
@rioV8, ya I am doing that now.But is there any other alternative to solve the issue?Brunell
G
6

To ignore error code in task of type shell, 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
            }
        }
    ]
}
God answered 9/6, 2022 at 23:45 Comment(4)
This ignores the error in the shell, not the task.Roe
@Roe right, answer fixedGod
be aware that "args" would applied to the last part of the command. In case some args are required those sould be part of the commandOotid
Alternatively, you can add ..."||", "echo", "0"], to the end of args for the same effect, if arguments are convenient/ required for your task.Protostele
M
1

In my case a simple Power Shell:

-ErrorAction Ignore 

Does the job, but it depends on what you're doing. Here's the reference for the shell.

Marrs answered 4/9, 2021 at 14:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.