pnp/cli-microsoft365

appCatalogScope sitecollection not working

Closed this issue ยท 13 comments

Priority

(Medium) I'm annoyed but I'll live

Description

I'm having trouble adding a sppkg to a catalog created within a subsite.

Even passing appCatalogScope sitecollection and appCatalogUrl information with the URL of the site, the app is being installed in the tenant's application catalog.
Here's my command line:

m365 spo app deploy --id $(appId) --appCatalogScope sitecollection --appCatalogUrl $(CatalogSite) -verbose

These variables are configured in my Pipeline, and work perfectly for catalogs that are in the root (tenant), now for a site where the catalog is inside the site, it ignores the URL that I am passing as appCatalogUrl.

NOTE: Just to clear up any doubts, the CatalogSite variable points to a subsite, for example: https://mysite.sharepoint.com/sites/demo

Steps to reproduce

I followed the example in the documentation on this page:
https://pnp.github.io/cli-microsoft365/cmd/spo/app/app-deploy

I added the -appCatalogScope property with the sitecollection value and inserted the -appCatalogUrl property with the URL of the site set's application catalog.

Expected results

What was expected was that it would install sppkg in the site catalog, but it's installing it in the root catalog (tenant).

Actual results

Through the log I can see where it is being installed, and it is pointed to /sites/appcatalog/appcatalog

2024-05-07T15:31:59.7474758Z "ServerRelativeUrl": "/sites/appcatalog/AppCatalog/hywork-lab.sppkg",

Diagnostics

No response

CLI for Microsoft 365 version

1.238.3

nodejs version

18.17.1

Operating system (environment)

Windows

Shell

PowerShell

cli doctor

No response

Additional Info

No response

Sorry to hear you are experiencing issues using CLI. We'll have a look at it.

@lhdeveloper which version of CLI are you exactly using? You can run m365 version to check it.

@lhdeveloper which version of CLI are you exactly using? You can run m365 version to check it.

I'm using the latest version.
As it's running in a pipeline, I always install m365 at the same time, so it's the latest version.

Hi, @lhdeveloper just had some time to do some tests. Unfortunately, I can't reproduce your issue.

I've added an app to my site collection app catalog:

image

After that, I deployed the app:

image

As you can see, the app is successfully uploaded and deployed.

image


To narrow down the issue, I think we have to clarify some things.

  • Which commands are you exactly running, the ones you specified are quite unclear to me. You are specifying a deploy command while you claim you are having problems uploading the sppkg file.
  • Could you run the commands with --debug flag and post the output here? This will make it a lot clearer what is exactly going on. You can always anonymize tenant info and remove access tokens in the output.
  • You claim you are using it in a pipeline. Do the commands work locally in your shell?

Sure, here's my output:

2024-05-07T15:31:59.7470476Z {
2024-05-07T15:31:59.7470839Z "CheckInComment": "",
2024-05-07T15:31:59.7471206Z "CheckOutType": 2,
2024-05-07T15:31:59.7472341Z "ContentTag": "{00506237-CB7D-4FCC-A3FB-5708BEB25A7D},1268,316",
2024-05-07T15:31:59.7472680Z "CustomizedPageStatus": 0,
2024-05-07T15:31:59.7472931Z "ETag": ""{00506237-CB7D-4FCC-A3FB-5708BEB25A7D},1268"",
2024-05-07T15:31:59.7473082Z "Exists": true,
2024-05-07T15:31:59.7473223Z "ExistsAllowThrowForPolicyFailures": true,
2024-05-07T15:31:59.7473356Z "ExistsWithException": true,
2024-05-07T15:31:59.7473471Z "IrmEnabled": false,
2024-05-07T15:31:59.7473612Z "Length": "21805270",
2024-05-07T15:31:59.7473714Z "Level": 1,
2024-05-07T15:31:59.7473833Z "LinkingUri": null,
2024-05-07T15:31:59.7473936Z "LinkingUrl": "",
2024-05-07T15:31:59.7474040Z "MajorVersion": 611,
2024-05-07T15:31:59.7474164Z "MinorVersion": 0,
2024-05-07T15:31:59.7474504Z "Name": "hywork-lab.sppkg",
2024-05-07T15:31:59.7474758Z "ServerRelativeUrl": "/sites/appcatalog/AppCatalog/hywork-lab.sppkg",
2024-05-07T15:31:59.7475031Z "TimeCreated": "2023-08-11T17:57:33Z",
2024-05-07T15:31:59.7475422Z "TimeLastModified": "2024-05-07T15:31:40Z",
2024-05-07T15:31:59.7475666Z "Title": "HyWork Intranet - Digital Workplace",
2024-05-07T15:31:59.7475960Z "UIVersion": 312832,
2024-05-07T15:31:59.7476096Z "UIVersionLabel": "611.0",
2024-05-07T15:31:59.7476308Z "UniqueId": "00506237-cb7d-4fcc-a3fb-5708beb25a7d"
2024-05-07T15:31:59.7476428Z }

In this case, the ServerRelativeUrl is pointing to the tenant's appcatalog, but the URL pointed to would be /sites/demonstracao/appcatalog.

Below is the entire execution of my pipeline task:

m365 login --authType certificate --certificateFile "$(certificateFile.secureFilePath)" --password "$(CertificatePassword)" --appId "$(RegisterAppID)" --tenant "$(TenantID)"
m365 spo set --url "$(SharePointBaseUrl)"
m365 spo app add -p $(System.DefaultWorkingDirectory)/_Deploy-Prod/drop/sharepoint/solution/hywork-lab.sppkg --overwrite --verbose
m365 spo app deploy --id $(appId) --appCatalogScope sitecollection --appCatalogUrl $(CatalogSite) --verbose ```

The problem is that you are using spo app add with its default values.
As you can see in the docs of spo app add you have to specify if you want to deploy it to a site collection app catalog.

-s, --appCatalogScope [appCatalogScope]
Scope of the app catalog. Allowed values: tenant, sitecollection. Defaults to tenant.

If you want to upload it to a site collection app catalog, you should run:

m365 spo app add -p $(System.DefaultWorkingDirectory)/_Deploy-Prod/drop/sharepoint/solution/hywork-lab.sppkg --overwrite --appCatalogScope sitecollection --appCatalogUrl "$(CatalogSite)"

@milanholemans but I have the app deploy line.
Are you telling me to use app add instead? I don't understand.
I see that they are different things.

In this case, I'm looking at the test documentation link:
https://pnp.github.io/cli-microsoft365/cmd/spo/app/app-deploy

And I'm doing exactly what it asks.

Should I declare the two flags in the spo app add as well?

@lhdeveloper please try to modify your script as follows and recheck

m365 login --authType certificate --certificateFile "$(certificateFile.secureFilePath)" --password "$(CertificatePassword)" --appId "$(RegisterAppID)" --tenant "$(TenantID)"

m365 spo set --url "$(SharePointBaseUrl)"

m365 spo app add --filePath $(System.DefaultWorkingDirectory)/_Deploy-Prod/drop/sharepoint/solution/hywork-lab.sppkg --appCatalogScope sitecollection --appCatalogUrl '$(CatalogSite)' --overwrite 

m365 spo app deploy --id $(appId) --appCatalogScope sitecollection --appCatalogUrl $(CatalogSite) 

let me know if it helped ๐Ÿ‘
Cheers

BTW if by any chance you are using Azure DevOps?
if so we have a command that will scaffold a YAML pipeline file and it also allows you to scaffold a flow that deploys to site level app catalog. You may generate and compare the script step if needed for reference
https://pnp.github.io/cli-microsoft365/cmd/spfx/project/project-azuredevops-pipeline-add

Alternatively you may use SPFx Toolkit CI/CD workflow action to do the same. It has a UI from to scaffold a pipeline either for GitHub or Azure DevOps

Thank you @Adam-it for clarifying.

@lhdeveloper deploying an app goes in 2 steps.
m365 spo app add will upload your sppkg file to your app catalog. So here we have to specify that you want to target your site collection app catalog.
After that, you have to run m365 spo app deploy to actually deploy the app that has been uploaded in the app catalog. Once again here, we have to say we want to target a site collection app catalog, so we have to specify it for this command as well.

Thanks for the feedback @Adam-it @milanholemans
I did just that and I'm testing the pipeline.

I already have everything configured and working, but I ran into this problem when uploading to a subsite.
I now understand that I have to point to the site on both lines. As in all the tenants I use, the catalog is in the tenant, I've never had a problem with this.

I believe that by adjusting the spo add line it will work as expected.
Thank you very much for your prompt replies.