【问题标题】:Git push from jenkins pipeline来自詹金斯管道的 Git 推送
【发布时间】:2020-02-13 09:48:07
【问题描述】:

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

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

【问题讨论】:

    标签: git jenkins github jenkins-pipeline pipeline


    【解决方案1】:

    有许多不同的方法可以实现这一目标。我使用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://&lt;username&gt;:&lt;token&gt;@github.com/&lt;username&gt;/&lt;repo&gt;.git 完成的,那么凭据将保留在 git 配置中,您不需要包含 --repo=${repoUrlWithAuth}

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

    another answer here 可能有助于解决这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-09
      • 2018-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-27
      • 2017-05-24
      相关资源
      最近更新 更多