通过 VSTS 发布时出现 CODE-PUSH 错误

CODE-PUSH error on release through VSTS

在 VSTS 上通过代码推送扩展推送版本时,我收到以下错误,不知道为什么!

尝试了以下解决方案之一,即在您的构建定义中添加名为 "Build.SourceDirectory" 的变量并获得以下错误日志

2017-11-17T09:13:07.6795222Z npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
2017-11-17T09:13:07.6795222Z ZUMOAPPNAME@1.0.0 d:\a\s
2017-11-17T09:13:07.6795222Z `-- (empty)
2017-11-17T09:13:07.6795222Z npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
2017-11-17T09:13:07.6795222Z 
2017-11-17T09:13:07.6835014Z npm WARN ZUMOAPPNAME@1.0.0 No description
2017-11-17T09:13:07.8445206Z npm WARN ZUMOAPPNAME@1.0.0 No license field.
2017-11-17T09:13:07.8465194Z npm ERR! Windows_NT 10.0.14393
2017-11-17T09:13:07.8475041Z npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" "cordova"
2017-11-17T09:13:07.8475041Z npm ERR! node v6.10.0
2017-11-17T09:13:07.8475041Z npm ERR! npm  v3.10.10
2017-11-17T09:13:07.8475041Z npm ERR! path d:\a\s\node_modules\cordova\node_modules\.bin\acorn.cmd
2017-11-17T09:13:07.8475041Z npm ERR! code EEXIST
2017-11-17T09:13:07.8475041Z 
2017-11-17T09:13:07.8475041Z npm ERR! Refusing to delete d:\a\s\node_modules\cordova\node_modules\.bin\acorn.cmd: ..\acorn\bin\acorn symlink target is not controlled by npm d:\a\s\node_modules\cordova\node_modules\acorn
2017-11-17T09:13:07.8475041Z npm ERR! File exists: d:\a\s\node_modules\cordova\node_modules\.bin\acorn.cmd
2017-11-17T09:13:07.8475041Z npm ERR! Move it away, and try again.
2017-11-17T09:13:07.8475041Z 
2017-11-17T09:13:07.8475041Z npm ERR! Please include the following file with any support request:
2017-11-17T09:13:07.8475041Z npm ERR!     d:\a\s\Client Components\Main\Source\vr9-11\npm-debug.log
2017-11-17T09:13:07.8475041Z npm ERR! code 1
2017-11-17T09:13:07.9305055Z ##[debug]load strings from: d:\a\_tasks\CodePushReleaseCordova_f5990527-f512-4c14-9f8e-1254240dc3cb.0.5\node_modules\vsts-task-lib\lib.json
2017-11-17T09:13:07.9325060Z Unhandled: Command failed: npm install cordova
2017-11-17T09:13:07.9325060Z ##[debug]load loc strings from: d:\a\_tasks\CodePushReleaseCordova_f5990527-f512-4c14-9f8e-1254240dc3cb.0.5\node_modules\vsts-task-lib\Strings\resources.resjson\en-US\resources.resjson
2017-11-17T09:13:07.9325060Z ##[debug]task result: Failed
2017-11-17T09:13:07.9365053Z ##[debug]Processed: ##vso[task.complete result=Failed;]Unhandled: Command failed: npm install cordova

日志文件可以在下面link看到:https://drive.google.com/open?id=1OC49xlDOEQekO9gqdrj0NQCMPz8onTRX

尝试了 Eddie 建议的解决方案(删除构建时重新生成的 bower 和 node 模块的文件)并得到以下错误。

2017-11-21T06:39:48.8214252Z ##[debug]Finished Building Command: node d:\a\_tasks\CodePushReleaseCordova_f5990527-f512-4c14-9f8e-1254240dc3cb.0.5\node_modules\code-push-cli\script\cli release-cordova "Syngenta_Visit_Report1" "android" --deploymentName "Staging" --rollout "100%"
2017-11-21T06:39:48.8254247Z ##[debug]Attempting execution of command: node d:\a\_tasks\CodePushReleaseCordova_f5990527-f512-4c14-9f8e-1254240dc3cb.0.5\node_modules\code-push-cli\script\cli release-cordova "Syngenta_Visit_Report1" "android" --deploymentName "Staging" --rollout "100%"
2017-11-21T06:39:49.6774368Z Running "cordova prepare" command:
2017-11-21T06:39:49.6774368Z 
2017-11-21T06:39:49.6874306Z 'cordova' is not recognized as an internal or external command,
2017-11-21T06:39:49.6904319Z operable program or batch file.
2017-11-21T06:39:49.6924371Z [Error]  Unable to prepare project. Please ensure that this is a Cordova project and that platform "android" was added with "cordova platform add android"
2017-11-21T06:39:49.7014305Z ##[debug]Finished Building Command: node d:\a\_tasks\CodePushReleaseCordova_f5990527-f512-4c14-9f8e-1254240dc3cb.0.5\node_modules\code-push-cli\script\cli logout
2017-11-21T06:39:50.5584321Z ##[debug]task result: Failed
2017-11-21T06:39:50.5624318Z ##[debug]Processed: ##vso[task.complete result=Failed;]Command failed: release-cordova
2017-11-21T06:39:50.5624318Z Command failed: release-cordova

任务从 Build.SourcesDirectory 文件夹的根目录运行 "cordova prepare" 命令,如 "d:\a\s"。我怀疑你的代码文件放在了像 "d:\a\s\yourappname" 这样的子文件夹中,这导致命令找不到项目。但是,任务中没有指定项目目录的选项。

作为解决方法,您可以在构建定义中添加一个名为 "Build.SourceDirectory" 的变量,如下所示:

首先确保您签入的文件夹在 node_modules 文件夹中没有任何文件,存在这些文件托管代理可能无法删除文件并且任务失败托管代理将下载通过检查 JSON 文件自行获取所需的文件。

为了解决这个错误:请在CodePush任务前添加两个任务:

1) 使用此设置添加 npm 任务

https://drive.google.com/open?id=1H4bWAMruzfOs90xOLxgjadAd7DihaVH4

2)在 npm 任务之后,添加具有以下设置的命令行任务

https://drive.google.com/open?id=1bxd54kVgW4zGRwhsH_JKz_cjc1wYZ-No

然后检查Cordova命令是否可以正确执行

那么如果你指定了变量Build.SourceDirectory

作为 $(Build.SourcesDirectory)\应用程序的路径

删除它(变量),因为您已经在 GET SOURCES 中指定了路径

您不需要在此条件下添加“Build.SourceDirectory”变量。现在,您将工作目录指定为“d:\a\s\app 路径”,它不应该存在于构建代理上,但任务没有报告该错误。

任务表明找不到 config.xml,因为该文件存在于“d:\a\s”而不是“d:\a\s\app 路径”下。

因此删除“Build.SourceDirectory”变量和运行要检查的构建

上述步骤应该适用于给定的问题

感谢 Eddie Chen 的帮助