我正在尝试使用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"
]
}
}
请注意“主页”和“部署”脚本。
在我的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
答案 0 :(得分:1)
我遇到了同样的问题,并通过在--repo
选项中提供Github令牌来解决了该问题。将npm run deploy
替换为
npx gh-pages --repo https://$(GITHUB_TOKEN)@github.com/org/repo.git -d dist
并将您的令牌添加为管道机密。