首页 > 解决方案 > 来自詹金斯管道的 Git 推送

问题描述

我想使用 jenkins 管道推送我的代码,那么有什么方法可以使用来自 jenkinsgit pushHTTPS吗?

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

标签: gitjenkinsgithubjenkins-pipelinepipeline

解决方案


有许多不同的方法可以实现这一目标。我使用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如果初始克隆是使用--repo=${repoUrlWithAuth}.

如果初始克隆具有正确的本地-远程分支映射,则不需要包含--set-upstream ${repoUrlWithAuth} ${sourceBranch}

这里还有另一个答案可能有助于解决这个问题。


推荐阅读