You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitLab Pipeline部署Azure静态Web应用无报错但未生效

问题:GitLab Pipeline部署Create React App到Azure静态Web应用无内容显示

我尝试通过GitLab Pipeline将基础Create React App部署到Azure静态Web应用,编写了如下.yml配置文件:

stages:
  - build
  - deploy

variables:
  API_TOKEN: $DEPLOYMENT_TOKEN
  APP_PATH: '$CI_PROJECT_DIR'
  OUTPUT_PATH: '$CI_PROJECT_DIR/build/'
  VERBOSE: 'true'

build:
  stage: build
  image: node:18.15.0-bullseye
  script:
    - npm install
    - npm run build
  artifacts:
    paths:
      - $OUTPUT_PATH

deploy:
  stage: deploy
  image: registry.gitlab.com/static-web-apps/azure-static-web-apps-deploy
  script:
    - echo "App deployed successfully."

构建和部署阶段均无报错,但Azure站点仍显示“Your Azure Static Web App is live and waiting for your content”提示,似乎未上传构建产物,不清楚如何获取更多诊断信息。

构建日志

Compiled successfully.
File sizes after gzip:
  46.61 kB  build\static\js\main.5a84f9dc.js
  1.79 kB   build\static\js\787.d8457f89.chunk.js
  541 B     build\static\css\main.073c9b0a.css
The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.
The build folder is ready to be deployed.
You may serve it with a static server:
  npm install -g serve
  serve -s build
Find out more about deployment here:
  https://cra.link/deployment
Uploading artifacts for successful job
00:03
Version:      16.3.1
Git revision: d240d5bb
Git branch:   16-3-stable
GO version:   go1.20.5
Built:        2023-09-14T23:38:58+0000
OS/Arch:      windows/amd64
Uploading artifacts...
Runtime platform                                    arch=amd64 os=windows pid=3776 revision=d240d5bb version=16.3.1
C:\Gitlab-Runner\builds\RNyC64A_\0\XXXX\secure-web-app/build/: found 20 matching artifact files and directories 
Uploading artifacts as "archive" to coordinator... 201 Created  id=20386 responseStatus=201 Created token=3stNxfN_
Cleaning up project directory and file based variables
00:02
Job succeeded

部署日志

Resolving secrets
00:00
Preparing the "shell" executor
00:00
Using Shell (powershell) executor...
Preparing environment
00:01
Running on XXXXXXX...
Getting source from Git repository
00:32
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in C:/Gitlab-Runner/builds/RNyC64A_/0/XXXX/secure-web-app/.git/
Checking out c333aa81 as detached HEAD (ref is master)...
Removing build/
Removing node_modules/
git-lfs/3.0.2 (GitHub; windows amd64; go 1.17.2)
Skipping Git submodules setup
Downloading artifacts
00:03
Version:      16.3.1
Git revision: d240d5bb
Git branch:   16-3-stable
GO version:   go1.20.5
Built:        2023-09-14T23:38:58+0000
OS/Arch:      windows/amd64
Downloading artifacts for build (20386)...
Runtime platform                                    arch=amd64 os=windows pid=26872 revision=d240d5bb version=16.3.1
Downloading artifacts from coordinator... ok        host=git.xxxx.com id=20386 responseStatus=200 OK token=3stNxfN_
Executing "step_script" stage of the job script
00:01
$ echo "App deployed successfully."
App deployed successfully.
Cleaning up project directory and file based variables
00:01
Job succeeded

解决方案

1. 核心问题:部署阶段未执行实际部署逻辑

当前deploy job仅输出提示文本,完全没有调用azure-static-web-apps-deploy镜像内置的部署脚本,导致构建产物从未上传到Azure平台。

2. 修正后的deploy阶段配置

deploy:
  stage: deploy
  image: registry.gitlab.com/static-web-apps/azure-static-web-apps-deploy
  script:
    - /bin/bash /usr/local/bin/deploy.sh
  variables:
    AZURE_STATIC_WEB_APPS_API_TOKEN: $API_TOKEN
    APP_LOCATION: "."
    OUTPUT_LOCATION: "build"
    VERBOSE: "true"
  dependencies:
    - build

3. 关键配置调整说明

  • 变量名映射:Azure部署镜像要求使用AZURE_STATIC_WEB_APPS_API_TOKEN作为部署令牌的变量名,需将原API_TOKEN映射到该变量。
  • 路径简化:部署镜像运行在Linux容器中,无需使用Windows风格的绝对路径,直接用相对路径即可(APP_LOCATION设为项目根目录.,OUTPUT_LOCATION设为build)。
  • 依赖指定:通过dependencies确保deploy阶段仅下载build阶段的artifacts,避免冗余操作。

4. 排查验证步骤

  • 确认GitLab项目CI/CD变量中DEPLOYMENT_TOKEN已正确设置为Azure静态Web应用的部署令牌。
  • 开启VERBOSE: "true"后,部署日志会输出详细的上传过程,可查看是否存在路径错误或权限问题。
  • 检查deploy阶段日志中是否有构建产物的解压记录,确认artifacts已正确下载到容器内。

内容的提问来源于stack exchange,提问作者frmrIntern

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 16:57:55