首页 > 解决方案 > 使用 Azure DevOps 在 Git 页面中部署 React 应用程序

问题描述

我正在尝试使用 Azure DevOps 在 git 页面中部署我的反应应用程序(只是一个非常基本的应用程序)。这是为了让我亲身体验 Azure Devops。

首先,我如下配置了我的 packag.json。

        {
      "name": "gitpages",
      "version": "0.1.0",
      "homepage": "https://senal.github.io/gitpage-react",
      "private": true,
      "dependencies": {
        "gh-pages": "^2.0.1",
        "react": "^16.8.6",
        "react-dom": "^16.8.6",
        "react-scripts": "3.0.1"
      },
      "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject",
        "predeploy": "npm run build",
        "deploy": "gh-pages -d build"
      },
      "eslintConfig": {
        "extends": "react-app"
      },
      "browserslist": {
        "production": [
          ">0.2%",
          "not dead",
          "not op_mini all"
        ],
        "development": [
          "last 1 chrome version",
          "last 1 firefox version",
          "last 1 safari version"
        ]
      }
    }

请注意“主页”和“部署”脚本。

在我的 Azure DevOps 中,我修改了 yml 文件,如下所示。

    # Node.js with React
    # Build a Node.js project that uses React.
    # Add steps that analyze code, save build artifacts, deploy, and more:
    # https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

    trigger:
    - master

    pool:
      vmImage: 'ubuntu-latest'

    steps:
    - task: NodeTool@0
      inputs:
        versionSpec: '10.x'
      displayName: 'Install Node.js'

    - script: |
        git config --global user.email "xxxx.yyyy@mymail.com"
        git config --global user.name "RSF"
        npm install
        npm run build
        npm run deploy
      displayName: 'npm install and build then deploy'

但是,当我在 DevOps 中运行构建时,出现以下错误:

    fatal: could not read Username for 'https://github.com': terminal prompts disabled

    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! gitpages@0.1.0 deploy: `gh-pages -d build`
    npm ERR! Exit status 1
    npm ERR! 
    npm ERR! Failed at the gitpages@0.1.0 deploy script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

    npm ERR! A complete log of this run can be found in:
    npm ERR!     /home/vsts/.npm/_logs/2019-06-13T12_03_34_094Z-debug.log
    ##[error]Bash exited with code '1'.

请就我的步骤/脚本提出建议。

如果您需要更多信息,请随时与我联系。

更新:我能够通过运行创建页面

npm 运行部署

从我的终端。

我想知道的是,为什么我们不能在 DevOps 中做同样的事情?

干杯,RSF

标签: reactjsazure-devopsgithub-pages

解决方案


--repo我遇到了同样的问题,并通过在选项中提供 Github 令牌来修复它。替换npm run deploy为,

npx gh-pages --repo https://$(GITHUB_TOKEN)@github.com/org/repo.git -d dist

并将您的令牌添加为管道密码。


推荐阅读