0

I'm trying to clone only the last commit but get the following error in the jenkins job:

+ git config credential.username ****
+ git config user.name jenkins
+ git config user.email jenkins@comp.com
+ git remote add origin https://bitbucket.org/base/my-repo.git

[Pipeline] sh
+ GIT_ASKPASS=true
+ git clone -b master --single-branch https://bitbucket.org/base/my-repo --depth=1 --bare ./last_commit
Cloning into bare repository './last_commit'...

fatal: could not read Username for 'https://bitbucket.org': No such device or address

This is the function that I'm using as Jenkins shared library:

def call(url, branch, gitCredentialId) {
    try {
        withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: gitCredentialId, usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) {
            sh("""                          
                git init
                git config credential.username ${env.GIT_USERNAME}
                git config user.name \"jenkins\"
                git config user.email \"jenkins@comp.com\"
                git remote add origin ${url}.git
            """)

            sh(returnStdout: false, script: """
                GIT_ASKPASS=true

                git clone -b ${branch} --single-branch ${url} --depth=1 --bare ./last_commit
                """)

            def email = sh(returnStdout: true, script: """
                cd ./last_commit
                git log -1 --format='%ae'
                """)

            return email.trim()
        }
    } finally {
        sh """
            git config --unset credential.username
            git config --unset credential.helper
        """
    }
}

What have I missed here? Has anyone faced the same issue? All I want to do to get the last comitter email.

Note that I have read this post here fatal: could not read Username for, No such device

Although it's the same error as mentioned but the difference is that, in that post the OP faces the error for an already-checked-out code and they try to push whereas I don't have issue with checking out the code (using git checkout). My issue is that I can't clone the repository and there is no pre-existing source

xbmono
  • 2,084
  • 2
  • 30
  • 50
  • Possible duplicate of [fatal: could not read Username for, No such device](https://stackoverflow.com/questions/42576857/fatal-could-not-read-username-for-no-such-device) Btw I was facing issues, once the password contained chars like `$`, `?` , etc... – xxxvodnikxxx Apr 09 '19 at 09:02
  • I think private repo URL mentioned is not proper. i think it will some thing like "git clone https://${USER}@bitbucket.org/${USER}/{repo}.git" – Rohit Jindal Apr 09 '19 at 09:17
  • or you can try with SSH inspite of https - > git clone git@bitbucket.org:${USER}/{repo}.git – Rohit Jindal Apr 09 '19 at 09:31
  • @xxxvodnikxxx I don't think that's the password, because we can do git checkout without any issue and with exactly the same code here – xbmono Apr 10 '19 at 00:09
  • @RohitJindal I run the same command in my local machine with the same URL fomat and it works just fine but this happens only in Jenkins – xbmono Apr 10 '19 at 00:11

0 Answers0