Git 多次提交 : Jenkins Pipeline

标签 git jenkins

我正在尝试使用以下代码在 Jenkins 管道中的单独提交中提交一些文件:

            sh '''
                git add $SOURCE_ENV/metadetail/current/*
                git commit -m "Updating Snapshot Metadata"
                git add $SOURCE_ENV/release/*
                git commit -m "Package for Release Branch"
                git push -u origin HEAD:$BRANCH_NAME
                git checkout master
                git checkout -b $BRANCH_NAMEfb
                git cherry-pick $BRANCH_NAME
                git push -u origin HEAD:$BRANCH_NAMEfb
            '''

这里的目标是在当前分支上进行两次单独的提交,从主分支创建一个新的功能分支,然后从原始分支中挑选第二次提交到新分支。 第一次提交后,jenkins 构建失败,并显示以下消息:

+ git commit -m Updating Snapshot Metadata
HEAD detached from 4b8ea1e
Untracked files:
    dPATCH/release/

nothing added to commit but untracked files present
script returned exit code 1

我不确定发生了什么 - 我的理解是只有“暂存”中的文件在提交时才重要,因此不确定为什么当我最初在子集上运行 git add 时会拾取其他文件文件的数量。有什么想法吗?

最佳答案

I'm not certain what is going on

正如我在“Adding git branch as a properties using Gradle on Jenkins”中提到的,默认情况下,Jenkins 会 checkout HEAD,而不是分支,将其工作区设置为分离的 HEAD 模式(因此是您的第一个提交输出)

在开始提交之前,您需要确保 checkout 分支。

参见Jenkins issue 6856: Git builds with detached head no matter what :

The "pipeline syntax" link on the left of most pipeline job pages will open a page where you can prototype the code you need to perform a checkout to a specific branch.
Use the "checkout" selection from that list (not the "git" selection), then select "Git" and add the "Additional Behaviours" for "Check out to specific local branch".
You can then set a specific branch name, or you can use "**" to indicate that it should use the branch name from the repository where the clone was performed.

关于Git 多次提交 : Jenkins Pipeline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46265313/

相关文章:

Git Copssh 不再免费,有哪些替代方案,以及如何在 Windows 上设置本地 Git 服务器

git - "git subtree pull"和 "git pull -s subtree"有什么区别

docker - 使用 docker 和 ansible iptables 拒绝传入流量

jenkins - 你什么时候必须在 Jenkins 找到一份新工作

git - 尝试在 Jenkins 上使用 SonarQube 来分析项目,但使用 JDK 1.7 的 Jenkins 出现不支持的主次版本错误

git - 在 Gerrit 中等待审查时,如何处理多个修复程序?

git - 我想让 git 给我一个文件夹中自给定修订以来未编辑的文件列表

git - 如何克隆 GIT 存储库列表?

jenkins - 如何将 github webhook 配置到 Google Cloud IAP 背后的 Jenkins 服务器

从 Jenkins 运行时,Ruby 无法正确理解安装了哪些 gem?