Travis CI-如何推入master分支? [英] Travis CI - How to push into master branch?
问题描述
我有一个连接到GitHub的Travis CI项目,该项目试图更新Github存储库中的内容并将其推回GitHub,包括master和gh-pages分支.
I have a Travis CI project connected to GitHub that tries to update content in the Github repo and push them back to GitHub, both master and gh-pages branches.
但是,尽管我的travis-ci日志文件说一切正常,但我只看到gh-pages分支已更新,但看不到master分支.
However, although my travis-ci log files says everything is ok, I only see the gh-pages branch updated, but not the master branch.
我的travis.yml文件是:
My travis.yml file is:
language: node_js
node_js: stable
language: python
python: 3.6
# Travis-CI Caching
cache:
directories:
- node_modules
- pip
# S: Build Lifecycle
install:
- npm install
- npm install -g gulp
- python -m pip install requests
- python -m pip install bs4
- python -m pip install lxml
before_script:
- cd archive_builder
- python build_archive.py
- cd ..
script:
- gulp dist
after_script:
- cd dist
- git init
- git config user.name "my git name"
- git config user.email "my git email"
- git add -A
- git commit -m "travis -- update gh-page"
- git push --force --quiet "https://${GH_TOKEN}@${GH_REF}" master:gh-pages
- sh ../purgeCF.sh $CF_ZONE $CF_KEY $CF_EMAIL
- cd ..
- git add -A
- git commit -m "travis -- update master files"
- git push --quiet "https://${GH_TOKEN}@${GH_REF}" HEAD:master
# E: Build LifeCycle
branches:
only:
- master
env:
global:
- GH_REF: github.com/mygitname/myprojectname.git
在此脚本中,我首先使用gulp更新和构建网站源文件,并将其存储在"dist"文件夹中.然后,我将"dist"中的内容推送到gh-pages分支,并将其他所有内容推送到我的master分支.
In this script, I first update and build website sourcefiles with gulp, storing them into "dist" folder. Then I push content in "dist" to my gh-pages branch, and push everything else to my master branch.
凭据与Travis一起存储为安全密钥,并且应该可以正常工作.
The credentials are stored as security keys with Travis and should work correctly.
要推送"dist/",我在"dist/"下创建了一个新的".git/",并强制将其推送为新的.
To push "dist/", I created a new ".git/" under "dist/" and force push it as new.
要推送其他所有内容,我无法做到,因为根存储库已经包含".git"文件夹,并且我不想丢失以前的提交.应该可以.
To push everything else, I could not do it because the root repository already contains ".git" folder and I do not want to lose my previous commits. It should work.
感谢您的帮助.
推荐答案
即使 @gary wang 方法有效,也有很多更简单的方法可以直接推送到GitHub master分支中.
Even though @gary wang method is working, there is much simpler method that can push into GitHub master branch directly.
只需在部署部分下添加 target_branch 变量,然后将其分配给 master .
Just add target_branch variable under deploy section, and assign it with master.
有关Travis CI GitHub页面部署的文档: https://docs.travis-ci.com/user/deployment/pages/
Documentation on Travis CI GitHub Pages Deployment: https://docs.travis-ci.com/user/deployment/pages/
.travis.yml 的内容示例:
language: node_js
...
...
...
deploy:
provider: pages
skip_cleanup: true
keep_history: true
github_token: $github_token # Your GitHub token set in Travis CI console
target_branch: master # Add this line - To push into GitHub master branch
on:
branch: staging # Your GitHub repo default branch
此方法已经过测试,可以按预期工作.
This method is tested and working as per expected.
这篇关于Travis CI-如何推入master分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!