You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在GitLab release-cli中配置多行Markdown发布描述?

解决GitLab release-cli创建多行Markdown描述发布的问题

你的问题出在直接在CI配置的release字段下写多行描述时,GitLab生成的shell命令会把换行直接展开,导致shell解析时出现语法错误。下面给两种靠谱的解决办法:

方法1:用临时文件传递描述(推荐)

把Markdown描述写入临时文件,再用release-cli的--description-file参数读取,这种方式支持任意复杂的Markdown格式,不用处理转义:

create release:
  stage: release
  image: registry.gitlab.com/gitlab-org/release-cli:latest
  script:
    # 单引号包裹EOF会阻止变量提前解析,去掉单引号则会自动替换$CI_COMMIT_TAG
    - |
      cat > release-description.md << 'EOF'
      Release created using the release-cli.

      Maven dependency
      ```xml
      <dependency>
        <groupId>group</groupId>
        <artifactId>artifact-id</artifactId>
        <version>$CI_COMMIT_TAG</version>
      </dependency>
      ```
      EOF
    # 通过文件读取发布描述
    - release-cli create --name "Release $CI_COMMIT_TAG" --tag-name $CI_COMMIT_TAG --description-file release-description.md
  only:
    - tags

方法2:手动转义换行符

如果不想用文件,可以把多行描述里的换行换成\n,并用双引号包裹,同时用反斜杠转义shell的换行:

create release:
  stage: release
  image: registry.gitlab.com/gitlab-org/release-cli:latest
  script:
    - |
      release-cli create \
        --name "Release $CI_COMMIT_TAG" \
        --tag-name $CI_COMMIT_TAG \
        --description "Release created using the release-cli.\n\nMaven dependency\n```xml\n<dependency>\n  <groupId>group</groupId>\n  <artifactId>artifact-id</artifactId>\n  <version>$CI_COMMIT_TAG</version>\n</dependency>\n```"
  only:
    - tags

注意:方法2需要手动处理所有换行转义,代码块里的换行也不能省略,适合简单场景;复杂Markdown格式优先用方法1。

内容的提问来源于stack exchange,提问作者Justin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 13:10:30