首页 > 解决方案 > 如何授予语义释放权限以将代码推送到 master

问题描述

semantic-release用来自动定义下一个版本,更新package.json并推送到git. 但是,我面临一个问题,它阻止我直接推送到master

我正在使用GitLab

我的release.config.js

module.exports = {
    "plugins": [
        "@semantic-release/commit-analyzer",
        "@semantic-release/release-notes-generator",
        "@semantic-release/changelog",
        "@semantic-release/npm",
        ["@semantic-release/git", {
            "assets": ["dist/**/*.{js,css}", "docs", "package.json"],
            "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
        }]
    ]
}

我的gitlab-ci.yml

package-versioning:
  stage: package-versioning
  tags:
    - fe
    - xdev
  artifacts:
    expire_in: 1 day
  only:
    refs:
      - master
  dependencies:
    - install
    - build
    - test
  script:
    - npx semantic-release --tag-format 'app/v${version}'

错误:

The command "git push --dry-run --no-verify https://gitlab-ci-token:[secure]@***/**.git HEAD:master" failed with the error message remote: You are not allowed to upload code.

fatal: unable to access 'https://gitlab-ci-token:[secure]@***/**.git/': The requested URL returned error: 403.

[6:02:23 PM] [semantic-release] › ✖  EGITNOPERMISSION Cannot push to the Git repository.
semantic-release cannot push the version tag to the branch next on the remote Git repository with URL https://gitlab-ci-token:[secure]@***/**.git.

但我实际上是 repo 的所有者,并且已经将master的推送权限设置为唯一所有者。我是否需要为脚本配置任何其他身份验证才能代表我运行?

所以我的问题是:

1/ 如何为语义发布设置身份验证,以便它可以代表您直接推送到主控

2/直接推送到master是一个好习惯(即使它只用于版本更新)。有没有人遇到过这种情况以及更新版本的解决方案是什么。非常感谢您的意见和想法。

标签: gitcontinuous-integrationcontinuous-deploymentsemantic-release

解决方案


1.在 GitLab 中,您必须明确设置要推送到 Git 的脚本。为此,您需要创建一个令牌并通过 env 变量将其传递给您的 CI。

例如,通过设置 GIT_PUSH_TOKEN 查看我们如何在集成项目中执行此操作 - 此处:https ://gitlab.com/taleodor/sample-helm-cd

以及此处的实际 ci yaml 代码:https ://gitlab.com/taleodor/sample-helm-cd/-/blob/master/.gitlab-ci.yml (第 25-30 行)。

2.是的,直接推送版本凹凸是常见的。


推荐阅读