Looks like I’m getting the same thing I’ve seen a bit on Google and here, but with Gogs rather than say gitlab. The clone step fails with this:
fatal: could not read Username for 'https://example.com': No such device or address
(the only thing I changed above was the hostname)
Using the debugging suggestion by bradrydzewski from https://github.com/drone/drone/issues/860:
docker run -i plugins/drone-git <<EOF
"clone_url": "https://user:[email protected]/Users/example.git"
This works, and doesn’t require netrc (which you can see, because I took that stanza out of the JSON).
It also seems to work if I change the repos.repo_clone field directly in the Drone database.
I’d love it if I didn’t have to tweak the DB for every repo… any ideas or advice is welcome!
Hi Robert, Drone uses the netrc to authenticate with GitHub, Bitbucket, GitLab and Gogs. I can confirm, as a Drone+Gogs user myself, that netrc authentication to private Gogs repositories works very well. It does not require manually editing the database.
There are a few different reasons, however, that you might get this error message. I have detailed these issues below:
- If you are using an older version of Gogs. There have been at least 2 major Gogs releases where the ability to authenticate with a Netrc was broken, and later fixed (see https://github.com/gogits/gogs/issues/2721).
- If your repository is public (any Gogs user can view) but Gogs is running in private mode (you need to have a Gogs username and password to view public repositories). In this case you need to set GOGS_PRIVATE_MODE per the installation instructions. When you activate the repository in Drone it will be treated as private, and credentials will be used to clone. IMPORTANT you need to enable private mode before first use. You cannot set this value after you have started using drone.
- If you added the repository to Drone and the repository was public, but then it was changed in Gogs to private. Drone will continue to think it is public and will not attempt to authenticate with credentials when cloning.
- If you are attempting to connect to Gogs using an IP address or custom hostname that is not accessible from inside a Docker container. This typically happens when someone tries to use a custom Docker hostname or localhost or loopback network address to access Gogs from inside the Drone container. This does not seem to be an issue for you, though, based on your test above.
- If you activate the repository with a user account, and then either delete that user account or revoke Drone’s access to that user account. This would cause problems because Drone will use this user’s oauth token in the netrc file to authenticate the git clone.
These are (off the top of my head) some of the common root causes for this issue.
Hey thank you very much! I’ll give these a try - I might actually start from scratch since I’m just testing things out.
I was facing the third issue which is similar for Gitea. I have public repo but when I have changed to private then I go
fatal: could not read Username for.... So what should be the workaround for if I want to keep private the repo now?
Drone does not authenticate when cloning a public repository. If you changed your repository from public to private you need to re-sync your account so that Drone can be made aware of this change and update its internal information, and in turn start authenticating when cloning.
Confirmed. It works!
Thanks for the advice.