drone-git-push icon indicating copy to clipboard operation
drone-git-push copied to clipboard

2FA and Github: how to solve could not read Username for 'https://github.com'

Open rdehuyss opened this issue 4 years ago • 3 comments

This is a follow-up for issue #43 . I just tried with a new release - still have some issues.

You can find drone.yml here: https://github.com/jobrunr/jobrunr/blob/master/.drone.yml.

What I try to do: update the Readme with the latest version (so the tag) How do I try it:

  - name: update readme
    image: jobrunr.io/build-container:1.0
    commands:
      - rm -f *.hprof
      - sed -i "s@<version>.*</version>@<version>${DRONE_TAG}</version>@g" README.md # replace version in README
      - sed -i "s@'org.jobrunr:jobrunr:.*'@'org.jobrunr:jobrunr:${DRONE_TAG}'@g" README.md # replace version in README
      - git config --global --add url."[email protected]:".insteadOf "https://github.com/" # Switch to ssh instead of https

  - name: push updated readme
    image: appleboy/drone-git-push
    settings:
      branch: master
      remote_name: origin
      ssh_key:
        from_secret: GITHUB_SSH_KEY
      force: false
      commit: true
      commit_message: "Update readme to new version [CI SKIP]"
      author_name: drone-bot
      author_email: [email protected]

The output for step push updated readme:

latest: Pulling from appleboy/drone-git-push
--
2 | Digest: sha256:144fd3130840d8ca0eba4b2aa98da027086d2d3fee6f2fbf4914564ad0a3b3f1
3 | Status: Image is up to date for appleboy/drone-git-push:latest
4 | + git add --all
5 | + git diff-index --quiet HEAD --ignore-submodules
6 | + git commit -m Update readme to new version [CI SKIP]
7 | + git push origin HEAD:master
8 | fatal: could not read Username for 'https://github.com': terminal prompts disabled
9 | exit status 128

Any idea on how to solve this?

Thanks again, Ronald

rdehuyss avatar May 26 '21 17:05 rdehuyss

As a workaround, you can manually set the remote parameter with your username and access token: https://<gh_username>:<gh_access_token>@github.com:repo.

Altogether, it's something like this with the code you provided:

  - name: push updated readme
    image: appleboy/drone-git-push
    settings:
      branch: master
      remote:
         from_secret: GH_REPO
      force: false
      commit: true
      commit_message: "Update readme to new version [CI SKIP]"
      author_name: drone-bot
      author_email: [email protected]

Alternatively, if you want to use the ssh key instead of the access token, you will still have to set the remote address by hand. Something like this works for me:

  - name: push updated readme
    image: appleboy/drone-git-push
    settings:
      branch: master
      remote_name: origin
      remote: [email protected]:<repo>
      ssh_key:
        from_secret: GITHUB_SSH_KEY
      force: false
      commit: true
      commit_message: "Update readme to new version [CI SKIP]"
      author_name: drone-bot
      author_email: [email protected]

pacbard avatar Jun 07 '21 12:06 pacbard

Thanks, I'll try it and report back.

rdehuyss avatar Jun 07 '21 12:06 rdehuyss

Hi

I am having the same issue, if I add an origin in the settings I get the following error:

+ git add --all
+ git diff-index --quiet HEAD --ignore-submodules
+ git remote add origin [email protected]:<repo>
error: remote origin already exists.
exit status 3

sevaho avatar Aug 09 '22 09:08 sevaho