Reactjs 使用Azure DevOps在Git页面中部署react应用程序

Reactjs 使用Azure DevOps在Git页面中部署react应用程序,reactjs,azure-devops,github-pages,Reactjs,Azure Devops,Github Pages,我正在尝试使用Azure DevOps在git页面中部署我的react应用程序(只是一个非常基本的应用程序)。这是为了让我的手沾湿Azure Devops 首先,我将packag.json配置如下 { "name": "gitpages", "version": "0.1.0", "homepage": "https://senal.github.io/gitpage-react", "private": true, "

我正在尝试使用Azure DevOps在git页面中部署我的react应用程序(只是一个非常基本的应用程序)。这是为了让我的手沾湿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"
        ]
      }
    }
    # 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'
请注意“主页”和“部署”脚本

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

        {
      "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"
        ]
      }
    }
    # 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我也有同样的问题,通过在
--repo
选项中提供Github令牌来修复它。将npm运行部署替换为

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

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

非常感谢您的回复。我会试试你提出的方法。