从提交消息中捕获软件包名称的脚本

发布于 2025-01-22 15:34:22 字数 733 浏览 0 评论 0原文

我正在尝试设置一个gitlab ci管道来删除软件包,只有在批准合并请求后,管道才会触发,并从$ ci_commit_message捕获软件包名称并将其传递到删除命令以删除软件包。

但是,我在推送( decomm-xxx )期间给出的$ ci_commit_message被添加了一些额外的行( merge branch 'ipl1'条件' 十字架 请参阅MR批准并合并后,请参见MERGE请求lkjdscjnjsdcdsnjkjkj“ )。

我如何从$ ci_commit_message中捕获包装名称,我最初给出( decomm-xxxxx ),我需要仅在“ decomm- ”之后打印文本,但我无法

对此进行任何帮助

”在此处输入图像说明”

I am trying to set up a GitLab ci pipeline to delete packages, the pipeline will trigger only after the merge request is approved, and the package name is captured from the $CI_COMMIT_MESSAGE and pass it to the delete command to delete the package.

But the $CI_COMMIT_MESSAGE which I have given during push (decomm-xxx) is been added with a few extra lines (Merge branch 'ipl1' into 'Condition'
decomm-zzz
See Merge request lkjdscjnjsdcdsnjkjkj"
) after the MR is approved and merged.

How exactly can I capture the package name from the $CI_COMMIT_MESSAGE which I originally gave (decomm-xxx), I need to print only the text after "decomm-" but I am not able to print it.

Any help on this would be much appreciated, thank you.

Below is the screenshot's which I tried.
enter image description here

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨落成白 2025-01-29 15:34:22

也许有几种方法:

  1. 停止GitLab添加额外的文本
  2. 编写脚本,以适应MR

更改提交消息

时添加的额外文本,以阻止Gitlab添加额外的文本,在Merge按钮下扩展下拉菜单。这将让您编辑合并提交消息:

”

编写一个更可靠的脚本

,您可以编写一个脚本以可靠地提取所需的文本。使用Regex可能是最合理的方法。

script:
  - pattern='decomm-([A-z]+)'  # adjust this pattern to suit your needs
  - '[[ "$CI_COMMIT_MESSAGE" =~ $pattern ]]'
  - CIMessage="${BASH_REMATCH[1]}"
  - echo "$CIMessage" # zzz

There's maybe a couple ways to do this:

  1. Stop gitlab from adding the extra text
  2. Write a script to accommodate the extra text added when merging an MR

Change the commit message

To stop GitLab from adding the extra text, expand the dropdown under the merge button. This will let you edit the merge commit message:

merge request UI

Write a more reliable script

Alternatively, you can write a script to reliably extract the text you need. Using regex is probably the most reasonable way to do this.

script:
  - pattern='decomm-([A-z]+)'  # adjust this pattern to suit your needs
  - '[[ "$CI_COMMIT_MESSAGE" =~ $pattern ]]'
  - CIMessage="${BASH_REMATCH[1]}"
  - echo "$CIMessage" # zzz
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文