0

我有以下吞咽任务:

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。所以上传任务失败。

我注意到的另一个我无法解释的工件是,当我运行 gulp 任务时,我看到了这个:

 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

4

1 回答 1

1

我认为上传任务将包上传到[租户|网站集]应用程序目录?这并不能解决您在帖子中遇到的问题,但是您是否考虑过使用适用于 Microsoft 365 的 CLI?它有一个命令可以为您执行此操作。

最重要的是,没有代码可以添加到项目的gulpfile.js中,也没有代码需要维护。效果很好...使用三个命令,您 (1) 登录、(2) 上传和 (3) 部署(即:信任)包。

# Sign into Microsoft 365
m365 login ${{ m365_target_site_url }} --authType password --userName ${{ m365_user_login }} --password ${{ m365_user_password }}
displayName: 

# Upload SharePoint package to Site Collection App Catalog
m365 spo app add --filePath ${{ sppkg_filepath }} --appCatalogUrl ${{ m365_target_site_url }}/AppCatalog --scope sitecollection --overwrite

# Deploy SharePoint package
m365 spo app deploy --name ${{ spPkgFileName}} --appCatalogUrl ${{ m365_target_site_url }} --scope sitecollection --skipFeatureDeployment
于 2021-08-31T17:38:00.393 回答