来自詹金斯管道的Git推送

时间:2020-02-13 09:48:07

标签: git jenkins github jenkins-pipeline pipeline

我想使用jenkins管道推送代码,那么有什么方法可以将jenkins的 HTTPS git push一起使用?

我们可以使用GitHub个人令牌进行git push吗?

1 个答案:

答案 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可能有助于找出答案。