【发布时间】:2020-02-13 09:48:07
【问题描述】:
我想使用 jenkins 管道推送我的代码,那么有什么方法可以将 git push 与 jenkins 的 HTTPS 一起使用?
我们可以使用 GitHub 个人令牌进行 git push 吗?
【问题讨论】:
标签: git jenkins github jenkins-pipeline pipeline
我想使用 jenkins 管道推送我的代码,那么有什么方法可以将 git push 与 jenkins 的 HTTPS 一起使用?
我们可以使用 GitHub 个人令牌进行 git push 吗?
【问题讨论】:
标签: git jenkins github jenkins-pipeline pipeline
有许多不同的方法可以实现这一目标。我使用sh 步骤来运行 git 命令。
在本地暂存并提交更改后,推送命令将如下所示
def repoUrlWithAuth = "https://<username>:<token>@github.com/<username>/<repo>.git"
def sourceBranch = "<branch-to-push-to>"
git push --repo=${repoUrlWithAuth} --set-upstream ${repoUrlWithAuth} ${sourceBranch}
如果初始克隆是使用 https://<username>:<token>@github.com/<username>/<repo>.git 完成的,那么凭据将保留在 git 配置中,您不需要包含 --repo=${repoUrlWithAuth}。
如果初始克隆具有正确的本地-远程分支映射,则无需包含--set-upstream ${repoUrlWithAuth} ${sourceBranch}
another answer here 可能有助于解决这个问题。
【讨论】: