简体   繁体   English

从 CI/CD 提交到存储库

[英]Committing from CI/CD into repository

I've recently configured one of my repositories to automatically deploy a release whenever I push a git tag matching "vX.YZ" , but this process isn't entirely automatic.我最近将我的一个存储库配置为在我推送匹配"vX.YZ"git tag时自动部署一个版本,但这个过程不是完全自动的。

Specifically, I have to update my version number in the source code (ie bump "vX.YZ" ) before I can tag it to be built.具体来说,我必须在源代码中更新我的版本号(即 bump "vX.YZ" ),然后才能将其标记为要构建。


So it seems I have a couple options所以看来我有几个选择

  1. Continue bumping the build number manually before tagging在标记之前继续手动修改内部版本号
  2. Have my CI update the build number (eg extract it from the tag) then commit the changes to master让我的 CI 更新内部版本号(例如从标签中提取它)然后将更改提交给master

In my opinion, bumping the version number manually is preferable because it requires more effort before deploying a release, and the releases are tied to the commit rather than being one commit behind in the case that CI has to update the version number.在我看来,手动修改版本号是可取的,因为在部署发布之前需要更多的努力,并且发布与提交相关联,而不是在 CI 必须更新版本号的情况下落后于一次提交。 (Also I don't want to wait for a build to finish deploying before updating master ) (我也不想在更新master之前等待构建完成部署)

I haven't been able to find a strong opinion online, so I'm curious:一直没能在网上找到比较强烈的意见,所以很好奇:

Is it considered bad practice to have my CI build server commit into my repository?将我的 CI 构建服务器提交到我的存储库是否被认为是不好的做法?

Is it considered bad practice to have my CI build server commit into my repository?将我的 CI 构建服务器提交到我的存储库是否被认为是不好的做法?

It it not consider a bad practice, but it creates more complexity and security concerns that should be balanced from the benefits.它不被认为是一种不好的做法,但它会产生更多的复杂性和安全问题,这些问题应该与好处相平衡。 Also remember that the process that you automate should be able to be executed manually in case of CI outage.还要记住,您自动化的过程应该能够在 CI 中断的情况下手动执行。

I think in your case there is a simpler solution.我认为在你的情况下有一个更简单的解决方案。 You could have the file in the source code that contains the version number not committed in the repository and be generated at build time from a script that pulls the latest tag.您可以在源代码中包含未在存储库中提交的版本号的文件,并在构建时从提取最新标签的脚本生成。 This way you would have a single point of truth for the release version (the tag) and the CI would not have to commit anything in the repository.通过这种方式,您将拥有发布版本(标签)的单一事实点,并且 CI 无需在存储库中提交任何内容。

I would recommend the followings, if you can use vX.YZ BuildVersion versioning scheme.如果您可以使用 vX.YZ BuildVersion版本控制方案,我会推荐以下内容。

  1. Manage vX.YZ by manually based on Semantic Versioning policy.根据语义版本控制策略手动管理vX.YZ。
  2. CI makes a release package with settting BuildVersion , if you push a new tag to GitHub.如果您将新标签推送到 GitHub,CI 会使用设置BuildVersion制作一个发布包。
    It would be the incremental count.这将是增量计数。
    Please note that BuildVersion is not managed on GitHub.请注意 BuildVersion 不在 GitHub 上管理。
  3. CI pushes the package to GitHub Release. CI 将包推送到 GitHub Release。

Elaborating on the initial question, which is ampler than the tag example.详细说明最初的问题,这比标签示例更丰富。 Some times our CI modifies the content of the repo before producing an artifact.有时,我们的 CI 在生成工件之前会修改 repo 的内容。 As an example imagine you have configuration files committed along with your application code.例如,假设您将配置文件与应用程序代码一起提交。 You normally would pack them together (eg in a Docker image) and then ship the image as the outcome of the build process.您通常会将它们打包在一起(例如在 Docker 映像中),然后将映像作为构建过程的结果发送。 If your CI is modifying those files by changing some values how would you treat them?如果您的 CI 通过更改某些值来修改这些文件,您将如何对待它们?

  • Commit the file back to the same repo without re-running the whole build would keep the config aligned but mess up the build process and might cause issues if the repo has been changed in the meantime.在不重新运行整个构建的情况下将文件提交回同一个 repo 会使配置保持一致,但会扰乱构建过程,如果在此期间 repo 已更改,则可能会导致问题。

  • Use the new config in the final artifact would be very easy but the artifact would not reflect the actual content of the repo if you look back.在最终工件中使用新配​​置将非常容易,但是如果您回头看,工件将不会反映 repo 的实际内容。

  • Externalizing those artifacts to a new repo would be an option but breaks the best practice to minimize the number of dependencies you need to build your application.将这些工件外部化到新的存储库是一种选择,但违反了将构建应用程序所需的依赖项数量最小化的最佳实践。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 重命名用于管道Ci / CD Runner的gitlab存储库 - Rename gitlab repository for pipeline Ci/CD runner 如何使用 GitLab CI/CD 获取整个存储库? - How to fetch entire repository with GitLab CI/CD? 从一个git存储库开始并提交到另一个 - Starting from one git repository and committing to another 使用CI / CD将我的git存储库的每个子目录部署到不同的目标 - Deploying each subdirectory of my git repository to a different target with CI/CD 从外部托管存储库提交内部非托管存储库的特定文件 - Committing specific files of inner unmanaged repository from an outer managed repository 如何防止开发人员提交到git存储库的某些文件夹 - How to prevent developers from committing into certain folders of git repository Azure DevOps CI/CD 和从源代码管理中分离连接字符串 - Azure DevOps CI/CD and Separating Connection Strings from Source Control 从发布(CD)管道触发构建(CI)管道? - Trigger Build (CI) pipeline from Release (CD )pipeline? Jenkins CI/CD - 将 Jenkinsfile 保存在我想要构建的单独存储库中 - Jenkins CI/CD - Keep the Jenkinsfile in a separte repository which I want to build 为什么 Git 提交到错误的存储库? - Why is Git committing to the wrong repository?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM