Ignore error from the preivous build task in tasks.json - visual-studio-code

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?

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
}
}
]
}

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.

Related

How to Debugger in VSCode?

I added new extension in VSCode. I've added syntax and snippets. It's time for debugging. I searched a lot and couldn't get exactly what I wanted. I want to debug without using tasks.json.
My json files:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Run",
"request": "attach",
"windows": {
"preLaunchTask": "windows"
},
"linux": {
"preLaunchTask": "linux"
},
"osx": {
"preLaunchTask": "osx"
}
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "windows",
"command": "echo",
"args": ["hello windows"],
"type": "shell"
},
{
"label": "linux",
"command": "echo",
"args": ["hello linux"],
"type": "shell"
},
{
"label": "osx",
"command": "echo",
"args": ["hello macOS"],
"type": "shell"
}
]
}
Thanks for all your answers.

Reduce finishing delay of VsCode task when called by "dependsOn"?

There is like a 500ms delay after completion of a task before running the next.
Are there any ways to reduce/remove this delay?
It can easily be tested by the pasting the following into tasks.json and run the task echo4
{
"label": "echo1",
"type": "shell",
"command": "echo 1",
},
{
"label": "echo2",
"type": "shell",
"command": "echo 2",
"dependsOn": "echo1",
},
{
"label": "echo3",
"type": "shell",
"command": "echo 3",
"dependsOn": "echo2",
},
{
"label": "echo4",
"type": "shell",
"command": "echo 4",
"dependsOn": "echo3",
},

VSCode Run Launch configuration via Tasks.json

I currently have a tasks.json that runs 3 tasks together, grouped in a panel on folder startup:
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Run dev",
"type": "shell",
"command": "npm run dev",
"presentation": {
"reveal": "always",
"panel": "new",
"group": "develop",
},
"runOptions": { "runOn": "folderOpen" }
},
{
"label": "Run css",
"type": "shell",
"command": "npm run watch:css",
"presentation": {
"reveal": "always",
"panel": "new",
"group": "develop",
},
"runOptions": { "runOn": "folderOpen" }
},
{
"label": "Run tunnel",
"type": "shell",
"command": "npm run tunnel",
"presentation": {
"reveal": "always",
"panel": "new",
"group": "develop",
},
"runOptions": { "runOn": "folderOpen" }
},
{
"label": "Start Dev",
"dependsOn": [
"Run dev",
"Run css",
"Run tunnel"
],
"problemMatcher": []
}
]
}
What i'm looking to do is move Run dev to a launch configuration instead so I have debugging enabled by default, and keep the same terminal experience:
launch.json
{
"configurations": [
{
"name": "Run npm run dev",
"command": "npm run dev",
"request": "launch",
"type": "node-terminal",
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"serverReadyAction": {
"pattern": "started at http://localhost:([0-9]+)",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}
So the end result will be the same 3 tasks, but "Run dev" triggers the "Run npm run dev" launch configuration in it's terminal window
The problem is there doesn't seem to be a way to do this?

VScode debug mode shows "Could not find the specified task"

When trying to start a Debug session in vscode, it throws an error about not finding a specified task. I've already tried the solutions of other SO questions like this but without success.
launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
...
},
{
"name": "MSEventHubs_Audit",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/audit-events.py",
"console": "integratedTerminal",
"args": [
"config/config.ini",
],
"envFile": "${workspaceFolder}/.env",
"env": {"PYTHONPATH": "${workspaceRoot}"},
"justMyCode": false,
"preLaunchTask": {
"task": "audit_tunnel"
}
},
{
...
},
]
}
tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"command": "",
"args": [],
"tasks": [
{
"label": "activate_key",
"type": "shell",
"command": "smartOS_card_pin.sh",
"args": [
"${inputs:cardos_pass}"
],
"group": "build",
},
{
"label": "audit_tunnel",
"type": "shell",
"group": "build",
"command": "ssh",
"args": [
"-NL",
"port1:127.0.0.1:port2",
"my_host"
],
"dependsOn": "activate_key"
},
{
...
}
],
"inputs": [
{
"id": "cardos_pass",
"type": "promptString",
"password": true
}
]
}
I've been looking at it for a while and cannot figure out what I'm doing wrong. The proof my task is known by vscode is when the pop-up message appears
I click 'Configure Task', the 'audit_tunnel' appears as an option to edit.
What am I missing?
Change:
"preLaunchTask": {
"task": "audit_tunnel"
}
To:
"preLaunchTask": "audit_tunnel"

Run another task from a task in VS Code

Is it possible to run task from another task?
For example I have two tasks: one print "Hello", another print "World":
{
"version": "2.0.0",
"tasks": [
{
"taskName": "printHello",
"type": "shell",
"command": "echo Hello",
"problemMatcher": []
},
{
"taskName": "printWorld",
"type": "shell",
"command": "echo World",
"problemMatcher": []
},
{
"taskName": "printHelloWorld",
"type": "shell",
"command": "...",
"problemMatcher": []
}
]
}
I added third tasks printHelloWorld which should first call task printHello and then printWorld.
Is it possible?