Deploy site

From microsoft/power-platform-skills · View interactive version

Deploy site is an AI agent skill from the GitHub repository microsoft/power-platform-skills. Deploys an existing Power Pages site to a Power Pages environment using PAC CLI. Routes SPA sites to the existing build and upload-code-site workflow, and PAC-downloaded non-SPA (classic) sites to an isolated upload workflow with explicit data-model and website-identity checks. Handles tooling verif

How to use this skill

Skill file

Plugin check: Run node "${PLUGIN_ROOT}/scripts/check-version.js" โ€” if it outputs a message, show it to the user before proceeding.

Deploy Power Pages Site

Route to the correct deployment workflow before running SPA build, attachment, or activation

logic.

Core Principles

Initial request: $ARGUMENTS


Site-Type Routing

Classify explicit request signals first:

or website.yml โ†’ Non-SPA site

When the request is not explicit, search the current workspace for:

.powerpages-site/.

Exclude dependency, build-output, temporary, generated-output, and version-control directories.

Use request paths and the current directory to resolve one project. Never choose the first result

arbitrarily.

<!-- gate: deploy-site:0.project-type | category=plan | cancel-leaves=nothing -->

๐Ÿšฆ Gate (plan ยท deploy-site:0.project-type): Select the exact project when SPA and

non-SPA sites, or multiple valid roots, remain possible.

Trigger: Project type or root is ambiguous after discovery.

Why: The two site types require incompatible PAC upload commands.

Cancel leaves: Nothing; no build or upload has started.

If ambiguous, use AskUserQuestion to select the exact project root and detected type.

${PLUGIN_ROOT}/skills/deploy-site/workflows/non-spa-site.md. Do not continue into the

SPA phases below.

Non-SPA upload approval

The authoritative markers and prompts live in workflows/non-spa-site.md.

Gate deploy-site:non-spa-4.permissions-audit handles permission-sensitive changes before upload.

Gate deploy-site:non-spa-5.upload approves the exact root, environment, website identity, model, and local change summary immediately before upload.

SPA-Site Deployment Workflow

The following phases retain the existing SPA behavior.


Phase 1: Verify PAC CLI

Goal: Ensure PAC CLI is installed and available on the system PATH

Actions:

  1. Create todo list with all 6 phases (see Progress Tracking table)
  2. Run pac help to check if the PAC CLI is installed and available on the system PATH.

```bash

pac help

```

  1. If the command succeeds: PAC CLI is installed. Proceed to Phase 2.
  1. If the command fails (command not found / not recognized):

1. Inform the user that PAC CLI is required but not installed.

2. Fetch installation instructions from https://aka.ms/PowerPlatformCLI using the following approach:

```bash

dotnet tool install --global Microsoft.PowerApps.CLI.Tool

```

3. After installation, verify by running pac help again.

4. If it still fails, stop and ask the user to resolve the installation manually.

Output: PAC CLI installed and verified


Phase 2: Verify Authentication

Goal: Ensure the user is authenticated with PAC CLI and has a valid session

Actions:

  1. Run pac auth who to check the current authentication status.

```bash

pac auth who

```

  1. If authenticated: Extract the following values from the output:

Proceed to Phase 3.

  1. If not authenticated:

1. Inform the user they are not authenticated with PAC CLI.

<!-- not-a-gate: free-text env URL fallback when PAC CLI auth is missing โ€” data-gathering, no destructive action -->

2. Use AskUserQuestion to ask for the environment URL:

| Question | Header | Options |

|----------|--------|---------|

| You are not authenticated with PAC CLI. Please provide your Power Pages environment URL (e.g., https://org12345.crm.dynamics.com) so I can authenticate you. | Auth | (free text input via "Other") |

Provide two placeholder options to guide the user:

3. Once the user provides the URL, run the authentication command:

```bash

pac auth create --environment "<USER_PROVIDED_URL>"

```

This will open a browser window for the user to sign in.

4. After the command completes, verify by running pac auth who again.

5. If authentication succeeds, proceed to Phase 3.

6. If authentication fails, present the error to the user and help them troubleshoot.

Output: Authenticated PAC CLI session with environment name and URL extracted


Phase 3: Confirm Environment

Goal: Ensure the user is deploying to the correct target environment

Actions:

<!-- gate: deploy-site:3.confirm-env | category=consent | cancel-leaves=nothing -->

๐Ÿšฆ Gate (consent ยท deploy-site:3.confirm-env): Echo the current environment and require explicit confirmation before any upload. Covers the follow-up "pick a different env" sub-prompt in the same section โ€” wrong-env deploys are the #1 destructive shared-state failure for this skill, so this gate must fire even when PAC CLI shows a recognizable env.

Trigger: Phase 3 entry; environment resolved from PAC CLI.

Why we ask: Site uploaded to wrong tenant / wrong env โ€” committed to a Dataverse instance the user did not intend; cleanup requires manual deletion or another deploy from a different env.

Cancel leaves: Nothing โ€” no upload fired.

  1. Present the current environment information to the user and ask them to confirm.

Use AskUserQuestion with the following structure:

| Question | Header | Options |

|----------|--------|---------|

| You are currently connected to environment: <ENV_NAME> (<ENV_URL>). Do you want to deploy to this environment? | Environment | Yes, use this environment, No, let me choose a different one |

  1. If "Yes, use this environment": Proceed to Phase 4.
  1. If "No, let me choose a different one":

1. Run pac org list to retrieve all available environments:

```bash

pac org list

```

2. Parse the output to extract environment names and URLs.

3. Use AskUserQuestion to present the available environments as options (pick up to 4 most relevant, or let user specify).

4. Once the user selects an environment, switch to it:

```bash

pac org select --environment "<SELECTED_ENV_ID_OR_URL>"

```

5. Verify the switch by running pac auth who again.

Output: Confirmed target environment for deployment


Phase 4: Deploy the SPA Site

Goal: Locate the project, build it, and upload to Power Pages

Actions:

4.1 Locate the Project Root

Determine the project root directory. The project root is the directory containing powerpages.config.json. Use Glob to search for it:

**/powerpages.config.json

<!-- gate: deploy-site:4.1.multi-project | category=plan | cancel-leaves=nothing -->

๐Ÿšฆ Gate (plan ยท deploy-site:4.1.multi-project): More than one powerpages.config.json candidate found โ€” pick the right project to deploy.

Trigger: Phase 4.1 glob returned multiple matches.

Why we ask: Wrong project uploaded โ€” pollutes the target env with files from a different site.

Cancel leaves: Nothing โ€” no upload fired.

If found in the current working directory or a subdirectory, use that directory as PROJECT_ROOT. If multiple are found, ask the user which one to deploy using AskUserQuestion.

If not found, ask the user to provide the path to the project root.

4.2 Offer Permissions Audit (Redeployments Only)

If .powerpages-site already exists (i.e., this is not the first deployment), table permissions and site settings may have drifted from the code since the last deployment. Offer to audit before deploying.

<!-- gate: deploy-site:4.2.audit-permissions | category=plan | cancel-leaves=nothing -->

๐Ÿšฆ Gate (plan ยท deploy-site:4.2.audit-permissions): Re-deployment detected โ€” offer to run /audit-permissions to catch drift between code and table permissions before push.

Trigger: .powerpages-site exists (not first deployment).

Why we ask: Stale permission YAML deploys, causing 403s for users until next audit run.

Cancel leaves: Nothing โ€” audit is read-only; declining just proceeds to build + upload.

Use AskUserQuestion:

| Question | Header | Options |

|----------|--------|---------|

| This site has been deployed before. Would you like to run a permissions audit to verify table permissions match your current code before deploying? | Audit | Yes, audit permissions (Recommended), Skip โ€” permissions are up to date |

If "Yes": Invoke /audit-permissions to run the audit. After the audit completes, resume with Step 4.3.

If "Skip": Proceed to Step 4.3.

If .powerpages-site does not exist (first deployment), skip this step โ€” there are no existing permissions to audit.

4.3 Build the Site

Before uploading, ensure the site is built:

cd "<PROJECT_ROOT>"
npm run build

If the build fails, stop and help the user fix the build errors before retrying.

4.4 Upload to Power Pages

Run the upload command:

pac pages upload-code-site --rootPath "<PROJECT_ROOT>"

If the upload succeeds: Proceed to Phase 5 to verify the deployment.

If the upload fails: Check the error message:

Output: Site built and uploaded to Power Pages


Phase 5: Verify Deployment

Goal: Confirm the deployment was successful and handle post-deployment steps

Actions:

5.1 Verify `.powerpages-site` Folder

Confirm .powerpages-site exists and list its contents (web-roles/, site-settings/, table-permissions/).

5.2 Record Skill Usage

Reference: ${PLUGIN_ROOT}/references/skill-tracking-reference.md

Follow the skill tracking instructions in the reference to record this skill's usage. Use --skillName "DeploySite".

5.3 Confirm Upload Output

Review the output from the pac pages upload-code-site command in Phase 4 (or Phase 6 retry). Verify it reported a successful upload with no errors.

5.4 Commit Changes

Stage and commit deployment artifacts:

git add -A
git commit -m "Deploy site to Power Pages"

5.5 Check Activation Status

Run the activation status check:

node "${PLUGIN_ROOT}/scripts/check-activation-status.js" --projectRoot "<PROJECT_ROOT>"

Evaluate the JSON result:

5.5.1 Ask About Activation (only if site is NOT already activated)

<!-- gate: deploy-site:5.5.1.activate | category=plan | cancel-leaves=nothing -->

๐Ÿšฆ Gate (plan ยท deploy-site:5.5.1.activate): Site deployed but not yet activated โ€” offer to invoke /activate-site to provision the subdomain.

Trigger: Phase 5.5 detected activated:false on a fresh deploy.

Why we ask: Auto-activating writes the wrong subdomain (permanent for the site); auto-skipping leaves the site without a live URL.

Cancel leaves: Nothing โ€” no activation API call fired.

Ask the user if they want to activate the site using AskUserQuestion:

| Question | Header | Options |

|----------|--------|---------|

| Site deployed successfully! Would you like to activate (provision) the site now so it gets a live URL? | Activate | Activate now (Recommended) โ€” Provision the site with a subdomain and make it live, Skip for now โ€” I'll activate later |

If "Activate now": Invoke the /activate-site skill. After activation completes, proceed to step 5.6 to clear the site cache.

If "Skip for now": Suggest next steps (see Suggest Next Steps).

5.6 Clear Site Cache (Only If Activated)

After confirming the site is activated (either it was already activated in step 5.5, or the user just activated it in step 5.5.1), offer to clear the runtime cache so the deployed changes are immediately visible.

Prerequisites: The site must be activated and the project root must be known (from Phase 4.1).

<!-- gate: deploy-site:5.6.restart-cache | category=plan | cancel-leaves=nothing -->

๐Ÿšฆ Gate (plan ยท deploy-site:5.6.restart-cache): Restart the deployed site to flush its runtime cache. Brief production downtime (a few seconds) โ€” explicit user consent required even though the action is recoverable.

Trigger: Site confirmed activated (either pre-existing or just activated in 5.5.1).

Why we ask: Production users see stale content for several minutes until cache TTL expires.

Cancel leaves: Nothing โ€” the deploy itself already succeeded; cache will refresh on its own.

Use AskUserQuestion to confirm before proceeding:

| Question | Header | Options |

|----------|--------|---------|

| Would you like to restart the site so your latest changes are immediately visible? This may cause a brief downtime (a few seconds). | Restart | Yes, restart site (Recommended), Skip โ€” I'll restart later |

If "Skip": Skip to Suggest Next Steps.

If "Yes": Run the cache-clearing script, passing the project root:

node "${PLUGIN_ROOT}/scripts/clear-site-cache.js" --projectRoot "<PROJECT_ROOT>"

The script reads siteName from powerpages.config.json, looks up the website via the Power Platform API, and restarts it to flush the runtime cache.

Evaluate the result:

Output: Deployment verified, changes committed, activation offered, cache cleared


Phase 6: Handle Blocked JavaScript

Goal: Resolve blocked JavaScript attachment errors and retry deployment

Actions:

6.1 Explain the Issue

Tell the user:

"The upload failed because JavaScript (.js) file attachments are blocked in your Power Pages environment. This is a security setting that prevents uploading .js files. To deploy a SPA site, this restriction needs to be relaxed for .js files."

6.2 Ask for Permission

<!-- gate: deploy-site:6.2.unblock-js | category=consent | cancel-leaves=attachment-block-modified -->

๐Ÿšฆ Gate (consent ยท deploy-site:6.2.unblock-js): Reactive blockedattachments modification โ€” destructive shared-state change (tenant-wide env setting). Same shape as deploy-pipeline:7.6.2.blocked-attachments.

Trigger: Upload failed with the blocked-.js error.

Why we ask: Auto-unblocking modifies a tenant security setting without explicit consent โ€” visible across the entire environment, not just this site.

Cancel leaves: attachment-block-modified is only possible if the user approved and then a downstream step partial-completed. Pure Cancel here leaves nothing โ€” the original blockedattachments value is untouched.

Use AskUserQuestion:

| Question | Header | Options |

|----------|--------|---------|

| Would you like to remove the JavaScript (.js) block from the environment's blocked attachments list? This is required to deploy SPA sites. | Unblock JS | Yes, remove the .js block (Recommended), No, do not change environment settings |

If "No": Stop and inform the user that the deployment cannot proceed without unblocking .js attachments.

If "Yes": Proceed to 6.3.

6.3 Update Blocked Attachments

  1. Run pac env list-settings to retrieve the current environment settings:

```bash

pac env list-settings

```

  1. Find the blockedattachments property in the output. It will contain a semicolon-separated list of file extensions (e.g., ade;adp;app;asa;ashx;asmx;asp;bas;bat;cdx;cer;chm;class;cmd;com;config;cnt;cpl;crt;csh;der;dll;exe;fxp;hlp;hta;htr;htw;ida;idc;idq;inf;ins;isp;its;js;jse;ksh;lnk;mad;maf;mag;mam;maq;mar;mas;mat;mau;mav;maw;mda;mdb;mde;mdt;mdw;mdz;msc;msh;msh1;msh1xml;msh2;msh2xml;mshxml;msi;msp;mst;ops;pcd;pif;prf;prg;printer;pst;reg;rem;scf;scr;sct;shb;shs;shtm;shtml;soap;stm;tmp;url;vb;vbe;vbs;vsmacros;vss;vst;vsw;ws;wsc;wsf;wsh).
  1. Remove js from the list. Parse the semicolon-separated values, filter out js, and rejoin with semicolons.
  1. Update the setting:

```bash

pac env update-settings --name blockedattachments --value "<UPDATED_LIST_WITHOUT_JS>"

```

  1. Confirm the update was successful.

6.4 Retry Upload

Run the upload command again:

pac pages upload-code-site --rootPath "<PROJECT_ROOT>"

If it succeeds: Proceed to Phase 5 to verify the deployment.

If it fails again with a different error, present the error to the user and help troubleshoot.

Output: JavaScript unblocked and site deployed successfully


Troubleshooting: HTML Blocked Attachment Error

If the upload fails with an error like:

Error: Unable to upload webfile name 'index.html' with record Id <GUID> as '.html' type attachments are currently blocked on this environment.

This error is misleading. The .html extension is not actually blocked โ€” the real cause is a stale environment manifest file in the .powerpages-site folder. This manifest maps local files to Dataverse record IDs from a previous upload. When the mapping becomes outdated (e.g., after environment changes or record deletions), the upload fails with this confusing error.

Fix

  1. Locate the environment-specific manifest file in the .powerpages-site folder. It follows the naming pattern <environment-host>-manifest.yml (e.g., demo1.crm.dynamics.com-manifest.yml). Use your file-search tool (e.g., Glob with pattern <PROJECT_ROOT>/.powerpages-site/*-manifest.yml) to find it.
  1. Delete the manifest file at <PROJECT_ROOT>/.powerpages-site/<environment-host>-manifest.yml.
  1. Retry the upload:

```bash

pac pages upload-code-site --rootPath "<PROJECT_ROOT>"

```

If the retry succeeds, proceed to Phase 5. If it fails with a different error, present the error to the user and help them troubleshoot.

Important: Do NOT attempt to unblock .html in the environment's blocked attachments list โ€” the error is not caused by the attachment block setting.


Suggest Next Steps

If the user skips activation (or after activation completes), suggest:


Important Notes

NEVER Use `pac pages upload`

Always use pac pages upload-code-site โ€” never use pac pages upload. The pac pages upload command is designed for portal-studio-style sites and will corrupt SPA site metadata if used on a SPA site project. This applies to every upload step in this skill (Phase 4.4, Phase 6.4, and troubleshooting retries).

Throughout All Phases

Key Decision Points (Wait for User)

  1. After Phase 2: If not authenticated, get environment URL from user
  2. At Phase 3: Confirm or switch the target environment
  3. At Phase 4.1: If multiple powerpages.config.json found, ask which project to deploy
  4. At Phase 4.2: Audit permissions now or skip (redeployments only)
  5. At Phase 5.5: Activate site now or later
  6. At Phase 6: Get permission before modifying blocked attachments setting

Progress Tracking

Before starting Phase 1, create a task list with all phases using TaskCreate:

| Task subject | activeForm | Description |

|-------------|------------|-------------|

| Verify PAC CLI installation | Verifying PAC CLI | Check if PAC CLI is installed, install if missing |

| Verify authentication | Verifying authentication | Check current auth status, authenticate if needed |

| Confirm target environment | Confirming environment | Show current environment, let user confirm or switch |

| Deploy the SPA site | Deploying site | Locate project root, build, and upload via pac pages upload-code-site |

| Verify deployment | Verifying deployment | Confirm .powerpages-site folder exists, review upload output, commit changes, offer activation |

| Handle blocked JavaScript | Resolving JS block | If upload fails due to blocked JS, offer to unblock and retry |

Mark each task in_progress when starting it and completed when done via TaskUpdate. Phase 6 may be marked completed immediately if no JavaScript blocking issue is encountered. This gives the user visibility into progress and keeps the workflow deterministic.


Begin with Phase 1: Verify PAC CLI

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.