git - 无法在 Jenkins 作业中进行 git clone
问题描述
我正在尝试仅克隆最后一次提交,但在 jenkins 作业中出现以下错误:
+ 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
这是我用作 Jenkins 共享库的函数:
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
"""
}
}
我在这里错过了什么?有没有人遇到过同样的问题?我想做的就是获得最后一封提交者的电子邮件。
请注意,我在这里读过这篇文章致命:无法读取用户名,没有这样的设备
虽然它与提到的错误相同,但不同之处在于,在那篇文章中,OP 面临已签出代码的错误,他们尝试推送,而我在签出代码时没有问题(使用git checkout
)。我的问题是我无法克隆存储库并且没有预先存在的源
解决方案
推荐阅读
- python - 在 Windows 上使用 PyCharm 安装 Scrapy 时出错?
- sql-server - 将本地数据库从本地 SQL Server 上传到 Azure
- android - Flutter 错误:(Webview)Media Query.of() 使用不包含媒体查询的上下文调用
- python - 如何将文本文件读入 Python 中的二维字符串列表
- apache-spark - spark writeStream 不适用于自定义 S3 端点
- javascript - 为什么我的随机性检查随机 num gen 不起作用?
- excel - While 循环,直到列中的每个单元格都满足条件
- mysql - MySQL 检查表是否仅包含此特定类型
- excel - 使用数据库时如何使用 Anylogic 对象 (INode) 作为类型
- fpdf - fpdf/php 对表格中的数据进行排序