I have PowerShell Script as a custom task inside a Build pipeline.
(我将PowerShell脚本作为Build管道中的自定义任务。)
The steps of these tasks are: (这些任务的步骤是:)
- Checkout a repositroy branch
(结帐存储库分支)
- Compile a solution in these branch
(在这些分支中编译解决方案)
- Copy the checkout and the compiling results to a server inside the network
(将结帐和编译结果复制到网络内部的服务器)
(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.
(为了使这些任务更加美观,我将此PowerShell脚本包装在一个自定义构建任务中。)
The index.ts
looks like:
(index.ts
看起来像:)
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(/(?:
|
|
)/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.
(因此,此自定义任务的唯一工作是调用PowerShell脚本。)
The Problem (问题)
If I execute the PowerShell script with a PowerShell Buildpipeline Task, everything is fine.
(如果我通过PowerShell Buildpipeline Task执行PowerShell脚本,一切都很好。)
The Task takes about 20 min , but every thing works. (该任务大约需要20分钟 ,但一切正常。)
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 )
(如果我执行包装的自定义任务,则在任务的3.阶段 ?11-12分钟后,该任务将引发错误( 将结帐和编译结果复制到网络内部的服务器中 ))
The Error Message (错误讯息)
[ps1] copy items from 'D:AzureDevOpsDataDeployGitFolder' to '\my-serverDeployGit' # <- 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:AzureDevOpsDataAgentAexternals
odein
ode.exe", Argumente ""D:AzureDevOpsDataAgentA\_work\_tasksDeployGit_ff191cd0-69d5-402d-aa18-9566fb6c511c1.0.6index.js"".
##[debug]Microsoft.VisualStudio.Services.Agent.Util.ProcessExitCodeException: Der Exitcode 5 wurde vom Prozess zurückgegeben: Dateiname "D:AzureDevOpsDataAgentAexternals
odein
ode.exe", Argumente ""D:AzureDevOpsDataAgentA\_work\_tasksDeployGit_ff191cd0-69d5-402d-aa18-9566fb6c511c1.0.6index.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.
(我对错误消息的解释是node.exe用退出代码5解决了错误。)
In this article windows use error code 5 for Access is denied
.
(在本文中, Windows使用错误代码5 Access is denied
。)
But it more feeling like node.exe can't handle the long copy process for any reason. (但它更让人感觉node.exe出于某种原因无法处理漫长的复制过程。)
Conclusion (结论)
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.
(对于这个长期的非常具体的问题,我感到抱歉,我只希望其他开发人员遇到类似的情况,因为我不知道这里发生了什么。)
ask by Mar Tin translate from so