我想使用jenkins管道推送代码,那么有什么方法可以将jenkins的 HTTPS 与git push
一起使用?
我们可以使用GitHub个人令牌进行git push吗?
答案 0 :(得分:1)
有许多不同的方法可以实现这一目标。我使用sh
步骤来运行git命令。
在本地暂存并提交更改后,push命令将类似于
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 config中,并且您无需包括--repo=${repoUrlWithAuth}
。
如果初始克隆具有正确的本地-远程分支映射,则无需包含--set-upstream ${repoUrlWithAuth} ${sourceBranch}
有another answer here可能有助于找出答案。