appleboy / drone-git-push

Drone plugin for deploying code using git push
Apache License 2.0
65 stars 36 forks source link

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

Open rdehuyss opened 3 years ago

rdehuyss commented 3 years ago

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."git@github.com:".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: drone-bot@jobrunr.io

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

pacbard commented 3 years ago

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: drone-bot@jobrunr.io

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: git@github.com:<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: drone-bot@jobrunr.io
rdehuyss commented 3 years ago

Thanks, I'll try it and report back.

sevaho commented 2 years ago

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 git@github.com:<repo>
error: remote origin already exists.
exit status 3