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