Sacha Durand
Sacha Durand

Reputation: 590

could not read Username for 'https://gitlab.com': No such device or address on Gitlab CI

I am trying to integrate gitlab CI on my node project, I have SSH access, but my script stop with error :

fatal: could not read Username for 'https://gitlab.com': No such device or address
debug2: channel 0: written 83 to efd 7
debug3: channel 0: will not send data after close
debug2: channel 0: obuf empty
debug2: channel 0: chan_shutdown_write (i3 o1 sock -1 wfd 6 efd 7 [write])
debug2: channel 0: output drain -> closed
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug3: send packet: type 97
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
#0 client-session (t4 r0 i3/0 o3/0 e[write]/0 fd -1/-1/7 sock -1 cc -1)
debug3: send packet: type 1
debug1: fd 0 clearing O_NONBLOCK
debug3: fd 1 is not O_NONBLOCK
debug1: fd 2 clearing O_NONBLOCK
Transferred: sent 3560, received 3156 bytes, in 0.7 seconds
Bytes per second: sent 5437.2, received 4820.2
debug1: Exit status 1
Cleaning up file based variables
00:01 ERROR: Job failed: exit code 1

I already tried

git config --global credential.helper store

git config --global user.password "myPassword"

git config --global user.email "myEmail"

Upvotes: 11

Views: 54107

Answers (3)

user23138211
user23138211

Reputation: 1

for those using .gitmodules and maybe private repositories and maybe gitlab 15.11.11-ee or similar and maybe using https and trying to get a gitlab runner to check out submodules:

this error can come up if your .gitmodules url has projectxxx rather than projectxxx.git in it - with various other credential setups it will work fine but when gitlab CI runs it you will have a log entry something like

warning: redirecting to [your_project_but_with_.git_at_the_end] 
fatal: could not read Username for [repo]: No such device or address
fatal: expected flush after ref listing
Unable to fetch in submodule path '[submodule path]; trying to directly fetch xxx'
warning: redirecting to [your_project_but_with_.git_at_the_end] 

where it adds .git to the submodule to fix your URL and successfully finds the submodule - but fails to carry across the gitlab-ci-token to the new URL request. So it tries to get the project without any authentication at all and fails

so check if you have the 'warning: redirecting to' log entries and if so fix by editing your .gitmodules file and adding .git to the end of the project URL

if this is your actual problem then related ideas that won't fix it for you however many times you run them:

  • using relative URLs instead of absolute URLs in .gitmodules
  • adding CI_JOB_TOKEN access in the submodule project to allow the calling project to use its CI_JOB_TOKEN with 'Allow access to this project with a CI_JOB_TOKEN' in submodule project->settings->token access

this used to work for me without .git in the project URLs to about Q3 2023 and now doesn't, so is a bug introduced somewhere by something

Upvotes: 0

d4n13lbc
d4n13lbc

Reputation: 5

This solution worked for me from gitlab https://wahlnetwork.com/2020/08/11/using-private-git-repositories-as-terraform-modules/ . In summary I setup a token and I executed the git config command from the pipeline

Upvotes: -2

Harshit Rastogi
Harshit Rastogi

Reputation: 2122

Try changing your repo origin on server using this command:

git remote set-url origin https://username:[email protected]/path_to_your_repo/repo.git

This way it won't ask for credentials while git pull or git push

Upvotes: 31

Related Questions