Skip to content

Commit

Permalink
Add signal handling to the BashV3 task
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanduplenskikh committed Dec 9, 2024
1 parent 478b013 commit 2d94f04
Show file tree
Hide file tree
Showing 38 changed files with 816 additions and 568 deletions.
328 changes: 220 additions & 108 deletions Tasks/BashV3/_buildConfigs/Node20/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Tasks/BashV3/_buildConfigs/Node20/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@types/mocha": "^9.1.1",
"@types/node": "^20.3.1",
"azure-pipelines-task-lib": "^4.16.0",
"azure-pipelines-task-lib": "^4.17.3",
"azure-pipelines-tasks-utility-common": "^3.230.0",
"uuid": "^3.0.1"
},
Expand Down
7 changes: 4 additions & 3 deletions Tasks/BashV3/bash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ async function run() {
ignoreReturnCode: true
};

process.on("SIGINT", () => {
tl.debug('Started cancellation of executing script');
bash.killChildProcess();
['SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGTERM', 'EXIT'].forEach((signal) => {
process.on(signal, () => {
bash.killChildProcess(signal as NodeJS.Signals);
});
});

// Listen for stderr.
Expand Down
96 changes: 48 additions & 48 deletions Tasks/BashV3/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Tasks/BashV3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@types/mocha": "^9.1.1",
"@types/node": "^16.18.105",
"azure-pipelines-task-lib": "^4.16.0",
"azure-pipelines-task-lib": "^4.17.3",
"azure-pipelines-tasks-utility-common": "^3.230.0",
"uuid": "^3.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion Tasks/BashV3/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 3,
"Minor": 246,
"Minor": 250,
"Patch": 0
},
"releaseNotes": "Script task consistency. Added support for multiple lines and added support for Windows.",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/BashV3/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 3,
"Minor": 246,
"Minor": 250,
"Patch": 0
},
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down
11 changes: 6 additions & 5 deletions Tasks/CmdLineV2/_buildConfigs/Node20/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Tasks/CmdLineV2/_buildConfigs/Node20/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/mocha": "^8.0.3",
"@types/node": "^20.3.1",
"@types/uuid": "^8.3.0",
"azure-pipelines-task-lib": "^4.15.0",
"azure-pipelines-task-lib": "^4.17.3",
"uuid": "^8.3.0"
},
"devDependencies": {
Expand Down
9 changes: 5 additions & 4 deletions Tasks/CmdLineV2/cmdline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function run() {
let workingDirectory = tl.getPathInput('workingDirectory', /*required*/ true, /*check*/ true);

if (fs.existsSync(script)) {
script = `exec ${script}`;
script = `exec bash ${script}`;
}

// Write the script to disk.
Expand Down Expand Up @@ -58,9 +58,10 @@ async function run() {
});
}

process.on("SIGINT", () => {
tl.debug('Started cancellation of executing script');
bash.killChildProcess();
['SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGTERM', 'EXIT'].forEach((signal) => {
process.on(signal, () => {
bash.killChildProcess(signal as NodeJS.Signals);
});
});

// Run bash.
Expand Down
102 changes: 51 additions & 51 deletions Tasks/CmdLineV2/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Tasks/CmdLineV2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/mocha": "^8.0.3",
"@types/node": "^16.11.39",
"@types/uuid": "^8.3.0",
"azure-pipelines-task-lib": "^4.15.0",
"azure-pipelines-task-lib": "^4.17.3",
"uuid": "^8.3.0"
},
"devDependencies": {
Expand Down
168 changes: 84 additions & 84 deletions Tasks/CmdLineV2/task.json
Original file line number Diff line number Diff line change
@@ -1,89 +1,89 @@
{
"id": "D9BAFED4-0B18-4F58-968D-86655B4D2CE9",
"name": "CmdLine",
"friendlyName": "Command line",
"description": "Run a command line script using Bash on Linux and macOS and cmd.exe on Windows",
"helpUrl": "https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line",
"helpMarkDown": "[Learn more about this task](https://go.microsoft.com/fwlink/?LinkID=613735)",
"category": "Utility",
"visibility": [
"Build",
"Release"
],
"runsOn": [
"Agent",
"DeploymentGroup"
],
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 246,
"Patch": 0
"id": "D9BAFED4-0B18-4F58-968D-86655B4D2CE9",
"name": "CmdLine",
"friendlyName": "Command line",
"description": "Run a command line script using Bash on Linux and macOS and cmd.exe on Windows",
"helpUrl": "https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line",
"helpMarkDown": "[Learn more about this task](https://go.microsoft.com/fwlink/?LinkID=613735)",
"category": "Utility",
"visibility": [
"Build",
"Release"
],
"runsOn": [
"Agent",
"DeploymentGroup"
],
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 250,
"Patch": 0
},
"releaseNotes": "Script task consistency. Added support for multiple lines.",
"showEnvironmentVariables": true,
"groups": [
{
"name": "advanced",
"displayName": "Advanced",
"isExpanded": false
}
],
"inputs": [
{
"name": "script",
"type": "multiLine",
"label": "Script",
"required": true,
"defaultValue": "echo Write your commands here\n\necho Hello world\n",
"properties": {
"resizable": "true",
"rows": "10",
"maxLength": "5000"
},
"helpMarkDown": ""
},
{
"name": "workingDirectory",
"type": "filePath",
"label": "Working Directory",
"defaultValue": "",
"required": false,
"groupName": "advanced"
},
{
"name": "failOnStderr",
"type": "boolean",
"label": "Fail on Standard Error",
"defaultValue": "false",
"required": false,
"helpMarkDown": "If this is true, this task will fail if any errors are written to the StandardError stream.",
"groupName": "advanced"
}
],
"instanceNameFormat": "Command Line Script",
"execution": {
"PowerShell3": {
"target": "cmdline.ps1",
"platforms": [
"windows"
]
},
"releaseNotes": "Script task consistency. Added support for multiple lines.",
"showEnvironmentVariables": true,
"groups": [
{
"name": "advanced",
"displayName": "Advanced",
"isExpanded": false
}
],
"inputs": [
{
"name": "script",
"type": "multiLine",
"label": "Script",
"required": true,
"defaultValue": "echo Write your commands here\n\necho Hello world\n",
"properties": {
"resizable": "true",
"rows": "10",
"maxLength": "5000"
},
"helpMarkDown": ""
},
{
"name": "workingDirectory",
"type": "filePath",
"label": "Working Directory",
"defaultValue": "",
"required": false,
"groupName": "advanced"
},
{
"name": "failOnStderr",
"type": "boolean",
"label": "Fail on Standard Error",
"defaultValue": "false",
"required": false,
"helpMarkDown": "If this is true, this task will fail if any errors are written to the StandardError stream.",
"groupName": "advanced"
}
],
"instanceNameFormat": "Command Line Script",
"execution": {
"PowerShell3": {
"target": "cmdline.ps1",
"platforms": [
"windows"
]
},
"Node10": {
"target": "cmdline.js",
"argumentFormat": ""
},
"Node16": {
"target": "cmdline.js",
"argumentFormat": ""
}
"Node10": {
"target": "cmdline.js",
"argumentFormat": ""
},
"messages": {
"GeneratingScript": "Generating script.",
"JS_ExitCode": "Bash exited with code '%s'.",
"JS_Stderr": "Bash wrote one or more lines to the standard error stream.",
"PS_ExitCode": "Cmd.exe exited with code '{0}'.",
"PS_UnableToDetermineExitCode": "Unexpected exception. Unable to determine the exit code from cmd.exe.",
"ScriptContents": "Script contents:"
"Node16": {
"target": "cmdline.js",
"argumentFormat": ""
}
},
"messages": {
"GeneratingScript": "Generating script.",
"JS_ExitCode": "Bash exited with code '%s'.",
"JS_Stderr": "Bash wrote one or more lines to the standard error stream.",
"PS_ExitCode": "Cmd.exe exited with code '{0}'.",
"PS_UnableToDetermineExitCode": "Unexpected exception. Unable to determine the exit code from cmd.exe.",
"ScriptContents": "Script contents:"
}
}
2 changes: 1 addition & 1 deletion Tasks/CmdLineV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 246,
"Minor": 250,
"Patch": 0
},
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down
4 changes: 2 additions & 2 deletions _generated/BashV3.versionmap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Default|3.246.0
Node20-225|3.246.1
Default|3.250.0
Node20-225|3.250.1
7 changes: 4 additions & 3 deletions _generated/BashV3/bash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ async function run() {
ignoreReturnCode: true
};

process.on("SIGINT", () => {
tl.debug('Started cancellation of executing script');
bash.killChildProcess();
['SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGTERM', 'EXIT'].forEach((signal) => {
process.on(signal, () => {
bash.killChildProcess(signal as NodeJS.Signals);
});
});

// Listen for stderr.
Expand Down
Loading

0 comments on commit 2d94f04

Please sign in to comment.