我正在尝试使用 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 "[email protected]"
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! [email protected] deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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
我遇到了同样的问题,并通过提供Github令牌在 --repo
选项。替换 npm run deploy
与:
npx gh-pages --repo https://$(GITHUB_TOKEN)@github.com/org/repo.git -d dist
并将你的token添加为管道秘密。