从Gulp调用NuGet.exe时出现EBUSY错误

时间:2017-03-01 22:41:16

标签: .net gulp nuget

我正在使用Gulp构建一个使用大量NuGet包的大型.NET解决方案。在过去六个月中,使用gulp-nuget-restore在编译之前获取软件包一直很好。

然而,我们最近购买了一个内部NuGet服务器,当我修改构建脚本以使用它时,它开始找不到System.Core(尽管nuget.org中的所有其他软件包仍然有效)。我怀疑罪魁祸首是nuget.exe的一个过时版本,它与gulp-nuget-restore软件包捆绑在一起;如果我用新版本手动覆盖它,那么构建将再次起作用。

所以,我现在正试图让Gulp脚本下载最新版本的nuget.exe并将其用于包恢复(这次是通过gulp-nuget NPM包)。奇怪的是,这在我的机器上完美运行,但在TeamCity构建服务器上失败了。

以下是我gulpfile.js的相关部分:

const gulp = require("gulp"),
    fs = require("fs"),
    nuget = require("gulp-nuget"),
    download = require("gulp-download-stream");

const nugetExePath = "./nuget.exe";

gulp.task("download-nuget", done => {
    if (fs.existsSync(nugetExePath)) {
        return done();
    }

    return download(
        {
            file: "nuget.exe",
            url: "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
        })
        .pipe(gulp.dest("."));
});

gulp.task("nuget-restore",
    ["download-nuget"],
    () => gulp.src("./mysolution.sln")
        .pipe(nuget.restore({
            nuget: nugetExePath,
            source: "http://our-internal-proget-server/nuget/Default/"
        })));

TeamCity构建日志:

[17:14:41][Step 2/2] Executing D:\TeamCity\buildAgent3\work\88991897ccf08f65\node_modules\.bin\gulp.cmd via wrapping shell script
[17:14:41][Step 2/2] Starting: cmd /c D:\TeamCity\buildAgent3\work\88991897ccf08f65\node_modules\.bin\gulp.cmd --no-color --teamcity.properties.all=D:\TeamCity\buildAgent3\temp\agentTmp\teamcity9135120293826835528.json     --teamcity.properties=D:\TeamCity\buildAgent3\temp\agentTmp\teamcity7511878459063399775.json --configuration Release --enableteamcity --buildnumber 1299
[17:14:41][Step 2/2] in directory: D:\TeamCity\buildAgent3\work\88991897ccf08f65
[17:14:44][Step 2/2] [17:14:44] Using gulpfile D:\TeamCity\buildAgent3\work\88991897ccf08f65\gulpfile.js
[17:14:44][Step 2/2] [17:14:44] Starting 'clean'...
[17:14:44][Step 2/2] [17:14:44] Starting 'set-build-number'...
[17:14:44][Step 2/2] [17:14:44] Starting 'download-nuget'...
[17:14:44][Step 2/2] [17:14:44] Downloading https://dist.nuget.org/win-x86-commandline/latest/nuget.exe...
[17:14:44][Step 2/2] [17:14:44] Finished 'clean' after 117 ms
[17:14:45][Step 2/2] [17:14:45] Updating assembly info file 'D:\TeamCity\buildAgent3\work\88991897ccf08f65\SharedAssemblyInfo.cs'...
[17:14:45][Step 2/2] [17:14:45]     Setting attribute 'AssemblyVersion' to '1.0.*.1299'.
[17:14:45][Step 2/2] [17:14:45]     Setting attribute 'AssemblyVersion' to '1.3.9.1299'.
[17:14:45][Step 2/2] [17:14:45]     Setting attribute 'AssemblyFileVersion' to '1.3.9.1299'.
[17:14:46][Step 2/2] [17:14:46] Finished 'set-build-number' after 1.67 s
[17:14:48][Step 2/2] [17:14:48] Downloaded https://dist.nuget.org/win-x86-commandline/latest/nuget.exe after 3.98 s
[17:14:48][Step 2/2] [17:14:48] Finished 'download-nuget' after 4.01 s
[17:14:48][Step 2/2] [17:14:48] Starting 'nuget-restore'...
[17:14:48][Step 2/2] [17:14:48] 'nuget-restore' errored after 5.17 ms
[17:14:48][Step 2/2] [17:14:48] Error: spawnSync ./nuget.exe EBUSY
[17:14:48][Step 2/2]     at exports._errnoException (util.js:1026:11)
[17:14:48][Step 2/2]     at spawnSync (child_process.js:461:20)
[17:14:48][Step 2/2]     at execFileSync (child_process.js:498:13)
[17:14:48][Step 2/2]     at Gulp.gulp.task (D:\TeamCity\buildAgent3\work\88991897ccf08f65\gulpfile.js:109:9)
[17:14:48][Step 2/2]     at module.exports (D:\TeamCity\buildAgent3\work\88991897ccf08f65\node_modules\orchestrator\lib\runTask.js:34:7)
[17:14:48][Step 2/2]     at Gulp.Orchestrator._runTask (D:\TeamCity\buildAgent3\work\88991897ccf08f65\node_modules\orchestrator\index.js:273:3)
[17:14:48][Step 2/2]     at Gulp.Orchestrator._runStep (D:\TeamCity\buildAgent3\work\88991897ccf08f65\node_modules\orchestrator\index.js:214:10)
[17:14:48][Step 2/2]     at D:\TeamCity\buildAgent3\work\88991897ccf08f65\node_modules\orchestrator\index.js:279:18
[17:14:48][Step 2/2]     at finish (D:\TeamCity\buildAgent3\work\88991897ccf08f65\node_modules\orchestrator\lib\runTask.js:21:8)
[17:14:48][Step 2/2]     at D:\TeamCity\buildAgent3\work\88991897ccf08f65\node_modules\orchestrator\lib\runTask.js:52:4
[17:14:48][Step 2/2] Process exited with code 1

"错误:spawnSync ./nuget.exe EBUSY"意味着某些东西仍然锁定nuget.exe文件,即使下载已经完成了吗?

提前感谢有关如何开始对此进行问题排查的任何建议。

1 个答案:

答案 0 :(得分:0)

这是一个可怕的黑客攻击,但是如果我在完成nuget.exe的下载后引入了1秒的时间延迟,那么错误就会消失:

const wait = require("gulp-wait");

gulp.task("download-nuget", done => {
    if (fs.existsSync(nugetExePath)) {
        return done();
    }

    return download(
        {
            file: "nuget.exe",
            url: "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
        })
        .pipe(gulp.dest("."))
        .pipe(wait(1000)); // Workaround for EBUSY error on TeamCity server.
});