Fatal: could not read Username for 'https://github.com': No such device or address


My pipeline is failing when pushing some changes to the remote repository. The below is the error attached.

sh + git push --set-upstream origin qa
fatal: could not read Username for ‘https://github.com’: No such device or address
[Pipeline] }

I have created a Personal Access Token and used that token as the password. After hitting this error i created a freestyle project “test” to see whether my git is configured correctly or not. Using that freestyle job i tried cloning the repository into my local machine and it got succeeded. That means my git is configured correctly (Correct me if i’m wrong) but why i’m getting this error when trying to push some configurations to the github.

Please let me know if you need any further info from my side to investigate this issue.

Appreciate your responses.

Prudhvi M.


The error message you’re seeing typically indicates that Git is trying to ask for a username and password, but it’s unable to do so because it’s running in a non-interactive environment (i.e., your Jenkins pipeline).

When you’re running Git commands in a Jenkins pipeline, you need to ensure that Git can authenticate with the remote repository without needing to prompt for a username or password. This is typically done by using SSH keys or a credential helper.

Since you’re using a Personal Access Token (PAT), you need to make sure that the token is correctly set up in your Jenkins pipeline. Here’s a general way to do it:

  1. Store your PAT in Jenkins credentials. You can do this by going to Manage Jenkins > Credentials > System > Global credentials > Add Credentials. Select “Username with password”, enter your GitHub username and PAT as the password, and hit Create.
  2. In your Jenkins pipeline, you need to use the withCredentials step to inject your credentials into the environment. Here’s an example:
withCredentials([usernamePassword(credentialsId: 'my-github', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) {
    sh '''
    git config --global user.name "${GIT_USERNAME}"
    git config --global user.password "${GIT_PASSWORD}"
    git push --set-upstream origin qa

Replace ‘my-github’ with the ID of the credentials you added in step 1. This will make your GitHub username and PAT available as environment variables in the sh step, and the git push command should be able to authenticate with GitHub without prompting for a username or password. Please note that this is a general solution and might need to be adjusted based on your specific Jenkins setup and pipeline script.

Hi @poddingue,

Thanks for your response…!!!

This is my checkout step in the pipeline Script, There i mentioned my credentialsID. Isn’t it not enough? Do i need to provide the withCredentials also in the checkout step? If yes, could you please help me where to mention it and how it looks.

checkout changelog: true, poll: true, scm: [class: 'GitSCM', branches: [[name: "origin/{params.branch}"]],
doGenerateSubmoduleConfigurations: false, extensions: [[$class: ‘ChangelogToBranch’,
options: [compareRemote: ‘origin’, compareTarget: ‘qa’]]], submoduleCfg: ,
userRemoteConfigs: [[credentialsId: ‘29e15550-26c7-4e2c-b2cc-4182525c7460’, url: ‘https://github.com/master-electronics/Angular-OMS.git’]]]

Appreciate more responses.

Prudhvi M.

Thanks @poddingue. i have added the withCredentials step in my pipeline and it worked fine.

1 Like

Thanks a lot for your feeback, @Prudhvi . :pray: