I’ve searched and I’ve searched, and I’ve tried so many different permutations/options that my head is spinning and I just can’t get this to work. All I’m trying to do is push back changes to GitHub if
However, I keep getting fatal: could not read Username for 'https://github.com': terminal prompts disabled in my logs. I’ve read Fatal: could not read Username for and tried all the steps there but nothing. What’s weird is that it works completely fine on a private repo. It’s only public repos (which are mine) that it doesn’t work.
I’ve also tried turning on DRONE_GIT_ALWAYS_AUTH to true, but still nada.
EDIT: Nevermind, apparently I hadn’t actually set the always auth variable/not restarted.
If you want to push to a repository, the recommended approach to providing credentials would be to use secrets to inject the credentials into your pipeline step (see an example here). We also provide a plugin that can be used to push code (see an example here).
I do not recommend using DRONE_GIT_ALWAYS_AUTH for this purpose. The DRONE_GIT_ALWAYS_AUTH flag is meant for teams that are using GitHub Enterprise behind the firewall with private mode enabled, which requires authentication to clone public repositories. If you enable this flag for GitHub cloud, a bad actor could send your public repository a pull request that intercepts your git credentials.
I use that plugin without issue (this is our real-world pipeline configuration and this is a successful build) however, if you are having issues with the plugin you should consult the plugin author or consider sending a pull request to help them patch.
Also keep in mind that Drone clones your repository using git+https. The reason you see an error (in the logs you posted above) is because the remote is git+https as opposed to git+ssh, and the ssh key cannot be used to authenticate a git+https remote. So if you want to push to your repository using an ssh key, you need to change the git remote to use the ssh repository url (e.g. git remote add upstream git@github.com:foo/bar.git; git push upstream master)
Back again, sorry. Trying to create a tag on the public Github repo and getting the same fatal: could not read Username for 'https://github.com': terminal prompts disabled
OK, i understand that now (never had dealt with HTTPS and git before). I see two options: 1) is it possible to push with something like an API key from Github? or 2) do something like this:
I was getting an invalid key format error which i’ve resolved by putting the SSH key in as a secret with \n for each line break and using echo -e. Now my issue is this:
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I’ve tested the key and it works/can authenticate against Github from another machine using the key.
In summary, there has to be an easier way to do this. Seems like a pretty basic thing to do.
In summary, there has to be an easier way to do this. Seems like a pretty basic thing to do.
The easiest option is to use the git push plugin (which we are using here). I understand you are having issues with the plugin but this is not something I can help you troubleshoot further. I recommend reaching out to the author directory or inspecting the source code (in the spirit of open source) to see if you can help the author improve.
I was getting an invalid key format error which i’ve resolved […]
Here is an of a real-world example that I used to clone a private repository that you can use for reference: http://discuss.harness.io/t/clone-private-submodule-for-public-project/1453/2. I noticed you are using slightly different commands, so maybe it is best to copy the technique at this link since it is proven to work.
Well the push plugin wouldn’t work with pushing a tag unless I’m missing something. It only can push commits. So it wouldn’t work for me as far as I can tell.
I managed to get this to work with HTTPS pushing using a Github API key.
- name: generate tag
image: alpine/git
environment:
GH_API_KEY:
from_secret: push_api_key
commands:
- git remote add github https://fuzzymistborn:$GH_API_KEY@github.com/FuzzyMistborn/dronetest.git
- git tag -a 0.0.1 -m "Release v. 0.0.1"
- git push -u github main 0.0.1