使用Gitlab CI创建Git日志

使用Gitlab CI创建Git日志,gitlab,gitlab-ci,git-commit,git-log,git-webhooks,Gitlab,Gitlab Ci,Git Commit,Git Log,Git Webhooks,当用户将代码提交到git存储库时,我们需要自动生成提交历史文件 可以使用Jenkins、Gitlab Webhooks和Jenkins Git Changelog插件完成。此外,还可以使用下面的git命令创建它 $ git log --pretty=format:'At %ci, %cN committed %h : %s' --decorate --graph >log.log 但是,我们是否可以使用Gitlab CI/CD操作生成提交历史文件。该文件可以保存在git Reposito

当用户将代码提交到git存储库时,我们需要自动生成提交历史文件

可以使用Jenkins、Gitlab Webhooks和Jenkins Git Changelog插件完成。此外,还可以使用下面的git命令创建它

$ git log --pretty=format:'At %ci, %cN committed %h : %s' --decorate --graph >log.log
但是,我们是否可以使用Gitlab CI/CD操作生成提交历史文件。该文件可以保存在git Repository或本地存储中

提交历史文件示例

* At 2018-11-16 18:02:21, kRiZ committed 1714a95 : Commit 4
* At 2018-11-15 16:06:06, kRiZ committed bab5c0c : Commit 3
* At 2018-11-14 18:05:09, kRiZ committed b3c9d86 : Commit 2
* At 2018-11-14 06:47:34, kRiZ committed 8e6ee30 : Add README.md

我相信在GitLab中有多种方法可以做到这一点。这里有一个:

  • 在存储库的根目录下创建一个
    .gitlab ci.yaml
    文件。您可以在本地或使用GitLab的web UI来执行此操作
  • 将此代码段粘贴到您的
    .gitlab ci.yaml
    文件中:

    changelog:
      image: docker:git
      script:
        - git log --pretty=format:'At %ci, %cN committed %h - %s' --decorate --graph >log.log
      artifacts:
        paths: [log.log]
    
  • 提交并在本地推送,或者在GitLab的Web UI上提交。将触发
    changelog
    作业

  • 作业成功完成后,您的
    log.log
    文件将作为
    changelog
    作业的工件提供
  • 本质上,通过这个代码片段,您可以将GitLab的CI/CD系统设置为:

    • 与预安装了git的Docker映像一起使用
    • 定义一个运行git命令的
      changelog
    • 定义将作为作业的一部分生成并存储的
      log.log
      ,以便以后可以下载
    我还建议查看所使用的也有可在任何地方使用的:

    npx git-changelog-command-line -std -tec "
    # Changelog
    
    Changelog for {{ownerName}} {{repoName}}.
    
    {{#tags}}
    ## {{name}}
     {{#issues}}
      {{#hasIssue}}
       {{#hasLink}}
    ### {{name}} [{{issue}}]({{link}}) {{title}} {{#hasIssueType}} *{{issueType}}* {{/hasIssueType}} {{#hasLabels}} {{#labels}} *{{.}}* {{/labels}} {{/hasLabels}}
       {{/hasLink}}
       {{^hasLink}}
    ### {{name}} {{issue}} {{title}} {{#hasIssueType}} *{{issueType}}* {{/hasIssueType}} {{#hasLabels}} {{#labels}} *{{.}}* {{/labels}} {{/hasLabels}}
       {{/hasLink}}
      {{/hasIssue}}
      {{^hasIssue}}
    ### {{name}}
      {{/hasIssue}}
    
      {{#commits}}
    **{{{messageTitle}}}**
    
    {{#messageBodyItems}}
     * {{.}} 
    {{/messageBodyItems}}
    
    [{{hash}}](https://github.com/{{ownerName}}/{{repoName}}/commit/{{hash}}) {{authorName}} *{{commitTime}}*
    
      {{/commits}}
    
     {{/issues}}
    {{/tags}}
    "
    

    但是,我们是否有办法更新gitlab存储库中的日志文件?或者除了在服务器或工件中保存日志文件之外的其他方式?