Reputation: 2412
I have PowerShell Script as a custom task inside a Build pipeline. The steps of these tasks are:
(because of some legacy stuff I can't compile the solution on the server directly)
To make these task more handsome, I wrap this PowerShell Script inside a custom build task.
The index.ts
looks like:
import tl = require('azure-pipelines-task-lib/task');
async function run() {
try {
//PARAMETERS
var params: string[] = ['Major', 'Minor', 'Work', 'Share', 'RepositoryUri', 'Branch', 'ProjectConfig', 'Include', 'Exclude'];
var required: boolean[] = [true, true, true, true, false, false, false, true, false];
var paramList: string[] = [];
//LOOP ALL PARAMETERS
for (let i = 0; i < params.length; i++) {
var item: string = tl.getInput(params[i], required[i]) || '';
if (item != null && item != '') paramList.push('-' + params[i] + ' ' + item.replace(/(?:\r\n|\r|\n)/g, ','));
}
//START CHILD PROCESS
var spawn = require('child_process').spawn, child;
console.log('##[command][js] call: powershell.exe ' + __dirname + '/DeployGit.ps1 ' + paramList.join(' '))
child = spawn('powershell.exe', [__dirname + '/DeployGit.ps1 ' + paramList.join(' ')]);
//REDIRECT CONSOLE OUTPUT
child.stdout.on('data', function (data: string) { console.log(data.toString()); });
child.stderr.on('data', function (data: string) { console.log(data.toString()); });
child.on('exit', function (code: number) { console.log('##[command][js] powershell exit code:', code); process.exit(code) });
child.stdin.end(); //END INPUT
}
catch (err) { tl.setResult(tl.TaskResult.Failed, err.message); process.exit(-1) }
}
run();
So the only job of this custom task is to call the PowerShell script.
If I execute the PowerShell script with a PowerShell Buildpipeline Task, everything is fine. The Task takes about 20 min, but every thing works.
If I execute the wrapped custom task the task throw an error after ~11-12 min in the 3. phase of the task (Copy the checkout and the compiling results to a server inside the network)
[ps1] copy items from 'D:\AzureDevOpsData\DeployGit\Folder' to '\\my-server\DeployGit' # <- LAST EXECUTET COMMAND [Copy-Item $Work -Destination $Share -Recurse -Force]
##[command][js] powershell exit code: 5
##[error]Der Exitcode 5 wurde vom Prozess zurückgegeben: Dateiname "D:\AzureDevOpsData\AgentA\externals\node\bin\node.exe", Argumente ""D:\AzureDevOpsData\AgentA\_work\_tasks\DeployGit_ff191cd0-69d5-402d-aa18-9566fb6c511c\1.0.6\index.js"".
##[debug]Microsoft.VisualStudio.Services.Agent.Util.ProcessExitCodeException: Der Exitcode 5 wurde vom Prozess zurückgegeben: Dateiname "D:\AzureDevOpsData\AgentA\externals\node\bin\node.exe", Argumente ""D:\AzureDevOpsData\AgentA\_work\_tasks\DeployGit_ff191cd0-69d5-402d-aa18-9566fb6c511c\1.0.6\index.js"".
at Microsoft.VisualStudio.Services.Agent.Util.ProcessInvoker.ExecuteAsync(String workingDirectory, String fileName, String arguments, IDictionary`2 environment, Boolean requireExitCodeZero, Encoding outputEncoding, Boolean killProcessOnCancel, IList`1 contentsToStandardIn, Boolean inheritConsoleHandler, CancellationToken cancellationToken)
at Microsoft.VisualStudio.Services.Agent.ProcessInvokerWrapper.ExecuteAsync(String workingDirectory, String fileName, String arguments, IDictionary`2 environment, Boolean requireExitCodeZero, Encoding outputEncoding, Boolean killProcessOnCancel, IList`1 contentsToStandardIn, Boolean inheritConsoleHandler, CancellationToken cancellationToken)
at Microsoft.VisualStudio.Services.Agent.Worker.Handlers.DefaultStepHost.ExecuteAsync(String workingDirectory, String fileName, String arguments, IDictionary`2 environment, Boolean requireExitCodeZero, Encoding outputEncoding, Boolean killProcessOnCancel, Boolean inheritConsoleHandler, CancellationToken cancellationToken)
at Microsoft.VisualStudio.Services.Agent.Worker.Handlers.NodeHandler.RunAsync()
at Microsoft.VisualStudio.Services.Agent.Worker.TaskRunner.RunAsync()
at Microsoft.VisualStudio.Services.Agent.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken jobCancellationToken)
##[section]Abschließen: Task: DeployGit.ps1
My interpretation of the error message is that node.exe thorws an error with the exit code 5.
In this article windows use error code 5 for Access is denied
. But it more feeling like node.exe can't handle the long copy process for any reason.
I used the custom wrapped tasks in many cases and it is the first time that I have a problem, maybe it is relatet to the long execution time?
I'am sorry for the long and the very specific problem, I only hoped that some other developer run into a similar situation, cause I have no idea what is going on here.
Upvotes: 1
Views: 1094
Reputation: 41745
Instaed of wrap the PowerShell script with TypeScript you can use the PS script directly in your custom build task.
In the task.json
you need to configure it in this way:
"execution": {
"PowerShell3": {
"target": "your-script.ps1",
"workingDirectory": "$(currentDirectory)"
}
}
You can check in this repo how to handle the inputs in the PowerShell script.
Upvotes: 2