通过travis ci失败承诺 [英] Committing via travis ci failing

查看:153
本文介绍了通过travis ci失败承诺的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 grunt-gh-pages 扩展程序来承诺我的gh -科。它在本地工作正常,但是当我使用TRAVIS-CI时,它失败了。它提供了以下错误消息 -

 警告:致命:远程错误:
您无法推送到git: //github.com/tusharmath/tusharm.com.git
使用https://github.com/tusharmath/tusharm.com.git
使用--force继续。

当我更新回购选项时,出现以下错误 - $ / b>

 警告:远程:匿名访问tusharmath / tusharm.com.git被拒绝。 
致命:'https://github.com/tusharmath/tusharm.com.git/'
认证失败使用--force继续。
由于警告而中止。

所以基本上我只是想让Travis-ci提交我的回购的gh-pages分支中的文件。有没有办法做到这一点?



更新最后 .travis.yml 那解决了问题

pre $语言:节点_js
node_js:
- '0.11'
before_script :
- git config --global user.emailtusharmath@gmail.com
- git config --global user.nameTravis-CI
after_script:
- git config credential.helperstore --file = .git / credentials
- echohttps:// $ {GH_TOKEN}:@ github.com> .git / credentials
- node ./node_modules/grunt-cli/bin/grunt release
env:
global:
secure:{lots-of-see-see-random-字符}


解决方案

第一个问题,就像您发现的,是因为使用 git:// URL来推送,但git协议只能用于克隆存储库。



至于匿名访问被拒绝错误,那是因为您需要让Travis登录到您的GitHub帐户才能推送到存储库。现在,你可能不想给Travis提供你的GitHub密码,你当然不需要。相反,我们将使用OAuth令牌。如果你不知道这意味着什么,别担心,我会解释。在大多数情况下,OAuth令牌的作用类似于密码,但更容易撤销访问单个事物。



要生成OAuth令牌,请转到 GitHub应用程序设置页面并点击Personal API Access Token下的Create new token。您可能希望为此添加注释,这样,如果将来需要跟踪并更容易撤销,则更容易。请注意,此令牌本质上是一个密码,因为它可以访问密码所做的相同事情。

然后,您需要将令牌添加到.travis.yml中文件。首先,我们将加密令牌,所以只有Travis可以看到它。为此,您需要安装 travis Rubygem: gem install tr​​avis

  travis encrypt GH_TOKEN =来自github的令牌--add 

您的.travis.yml应该如下所示:

  ... 
env:
global:
- secure:很多看似随机的字符
...

现在,为了让Travis真正使用此令牌,您还需要在.travis.yml中添加更多内容。



< pre $ after_script:
- git config credential.helperstore --file = .git / credentials
- echohttps:// $ {GH_TOKEN}: @ github.com> .git / credentials
- node ./node_modules/grunt-cli/bin/grunt release

这首先告诉git在 .git / credentials 文件中查找凭证。这可以是你想要的任何文件,但确保它不是你要推送给GitHub的文件。然后,我们将该标记添加到 .git / credentials 文件中。 Git现在知道推送到 https://github.com ,它可以使用您的令牌进行身份验证。



你应该全部设置好了!



PS:如果你只想在GitHub推送时通过,你可以改变 after_script after_success


I am trying to use grunt-gh-pages extension to commit to my gh-branch. It works fine locally but when I use TRAVIS-CI it fails. It gives the following error message -

Warning: fatal: remote error: 
  You can't push to git://github.com/tusharmath/tusharm.com.git
  Use https://github.com/tusharmath/tusharm.com.git
 Use --force to continue.

And when I update the repo option I get the following error -

Warning: remote: Anonymous access to tusharmath/tusharm.com.git denied.
fatal: Authentication failed for 'https://github.com/tusharmath/tusharm.com.git/'
 Use --force to continue.
Aborted due to warnings.

So basically I just want Travis-ci to commit the files in the gh-pages branch of my repo. Is there a way to do that?

Update The final .travis.yml that solved the problem

language: node_js
node_js:
  - '0.11'
before_script:
  - git config --global user.email "tusharmath@gmail.com"
  - git config --global user.name "Travis-CI"
after_script:
  - git config credential.helper "store --file=.git/credentials"
  - echo "https://${GH_TOKEN}:@github.com" > .git/credentials
  - node ./node_modules/grunt-cli/bin/grunt release
env:
  global:
    secure: {"lots-of-seemingly-random-characters"}

解决方案

You certainly can! The first issue, like you discovered, is due to using the git:// URL to push to, but the git protocol can only be used to clone repositories.

As for the "anonymous access denied" error, that's because you need to let Travis log in to your GitHub account in order to push to the repository. Now, you probably don't want to give Travis your GitHub password, and you certainly don't have to. Instead we're going to use OAuth tokens. If you have no idea what that means, don't worry, I'll explain. An OAuth token in most cases works like a password, but it's easier to revoke access to single things.

To generate an OAuth token, go to the GitHub Applications settings page and click "Create new token" under "Personal API Access Token". You probably want to add a note for what this is, that way it's easier to keep track of and easier to revoke if you need to in the future. Note that this token is essentially a password in that it gives access to the same things a password does.

Then, you need to add the token to your .travis.yml file. First, we'll encrypt the token so only Travis can see it. For this, you need the travis Rubygem installed: gem install travis.

travis encrypt GH_TOKEN="the-token-from-github" --add

Your .travis.yml should now look something like this:

…
env:
  global:
    - secure: "lots-of-seemingly-random-characters"
…

Now, in order for Travis to actually use this token, you need to add some more things to your .travis.yml too.

after_script:
  - git config credential.helper "store --file=.git/credentials"
  - echo "https://${GH_TOKEN}:@github.com" > .git/credentials
  - node ./node_modules/grunt-cli/bin/grunt release

This first tells git to look for credentials in the .git/credentials file. This can be any file you want, really, but make sure it's not one you're going to push to GitHub. Then, we add the token to the .git/credentials file. Git now knows that for pushes to https://github.com, it can use your token to authenticate.

You should be all set!

PS: If you only want to push to GitHub if the build passes, you can change after_script to after_success.

这篇关于通过travis ci失败承诺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆