我有以下大口任务:
build.task('upload', {
execute: (config) => {
/*
THIS WORKS, BUT ONLY if i do "gulp upload".
"gulp upload -u < commandline options >" fails.
const uname = "johndoe@asdf.com";
const pwd = "supersecret";
const siteUrl = "https://<mytenant>.sharepoint.com/sites";
const siteCatalogUrl = "https://<mytenant>.sharepoint.com/sites/CatalogSiteName";
const catalogName = "AppCatalog";
console.log(uname);
console.log(siteUrl);
console.log(siteCatalogUrl);
console.log(catalogName);
*/
const uname = config.args['u'];
const pwd = config.args['p'];
const siteUrl = config.args['sU'];
const siteCatalogUrl = config.args['cU'];
const catalogName = config.args['c'];
console.log(uname);
console.log(siteUrl);
console.log(siteCatalogUrl);
console.log(catalogName);
return new Promise((resolve, reject) => {
const pkgFile = require('./config/package-solution.json');
const folderLocation = `./sharepoint/${pkgFile.paths.zippedPackage}`;
return gulp.src(folderLocation)
.pipe(spsync({
"username": uname,
"password": pwd,
"site": siteCatalogUrl,
"libraryPath": catalog,
"publish": true
}))
.on('finish', resolve);
});
}
});
当我在命令行上进行测试时,我会这样运行:
gulp upload
它做的第一件事是调用gulp clean...这会吹走sppkg。所以上传任务失败。
我注意到的另一个我无法解释的假象是当我运行吞咽任务时,我看到了这个:
Build target: SHIP
而不是通常的
Build target: DEBUG
输出
lab3:search-parts admin$ gulp upload
Build target: SHIP
[14:16:31] Using gulpfile /src/search/gulpfile.js
[14:16:31] Starting 'upload'...
[14:16:31] Starting gulp
[14:16:31] Starting subtask 'clean'...
[14:16:31] Finished subtask 'clean' after 119 ms
[14:16:31] The following tasks did not complete: upload
[14:16:31] Did you forget to signal async completion?
About to exit with code: 0
Process terminated before summary could be written, possible error in async code not continuing!
Trying to exit with exit code 1
不知道有没有关系,但万一...
- 谢谢-谢谢
编辑1
我可以不断地重现这个问题,而且我也找到了一个修复方法--尽管--我不能在生产中使用。但是我还不知道问题的根本原因是什么。
要创建这个问题,我只需要通过config对象传入参数。换句话说,我通过命令行触发这个gulp方法,如下所示:
gulp package-solution --ship
gulp upload --u "johndoe@asdf.com" --p "supersecret" --sU "https://<mytenant>.sharepoint.com/sites/CatalogSiteName" --cU "https://<mytenant>.sharepoint.com/sites/CatalogSiteName" --c "AppCatalog"
当我运行这个脚本时,它做的第一件事就是一个大口的清理。如果我注解掉所有从config.args[]中获取变量的逻辑,只使用硬编码的值......它就可以工作了。但是我必须确保我没有通过命令行提供参数。换句话说,这是可行的:
lab3:spparts admin$ gulp upload
Build target: DEBUG
[14:27:27] Using gulpfile /src/sp/spparts/gulpfile.js
[14:27:27] Starting 'upload'...
[14:27:27] Starting gulp
johndoe@asdf.com
https://<mytenant>.sharepoint.com/sites/CatalogSiteName
https://<mytenant>.sharepoint.com/sites/CatalogSiteName
AppCatalog
[14:27:27] Uploading spparts.sppkg
[14:27:32] Upload successful 5289ms
[14:27:35] Published file 2408ms
[14:27:35] Finished 'upload' after 7.73 s
[14:27:35] ==================[ Finished ]==================
[14:27:36] Project spparts version:4.3.0
[14:27:36] Build tools version:3.17.11
[14:27:36] Node version:v10.24.1
[14:27:36] Total duration:13 s
但这并不能:(即使js代码仍使用硬编码值)
lab3:spparts admin$ gulp upload --u "johndoe@asdf.com" --p "supersecret" --sU "https://<mytenant>.sharepoint.com/sites/CatalogSiteName" --cU "https://<mytenant>.sharepoint.com/sites/CatalogSiteName" --c "AppCatalog"
Build target: SHIP
[14:27:27] Using gulpfile /src/sp/spparts/gulpfile.js
[14:27:27] Starting 'upload'...
[14:27:27] Starting gulp
[14:30:36] Starting subtask 'clean'...
[14:30:36] Finished subtask 'clean' after 68 ms
johndoe@asdf.com
https://<mytenant>.sharepoint.com/sites/CatalogSiteName
https://<mytenant>.sharepoint.com/sites/CatalogSiteName
AppCatalog
[14:30:36] 'upload' errored after 85 ms
[14:30:36] Error: File not found with singular glob: /src/spparts/sharepoint/solution/spparts.sppkg (if this was purposeful, use `allowEmpty` option)
总之,我想我可以说,当我传入命令行参数时,脚本调用gulp clean。但我不知道为什么。
如果有帮助的话,这里是我的版本信息:
lab3:spparts admin$ gulp -v
CLI version: 2.3.0
Local version: 4.0.2
sp-build-web的版本是1.12.1
1条答案
按热度按时间5lwkijsr1#
我认为upload任务会将包上传到[租户|站点集合]应用程序目录?这并不能解决你在帖子中的问题,但是你有没有考虑过使用Microsoft 365的CLI?它有一个命令可以帮你做到这一点。
最棒的是,不需要在项目的gulpfile.js中添加代码,也不需要维护代码。信任)该包。