如何授予语义释放权限以将代码推送到主站点 [英] How to grant permission for semantic-release to push code to master

查看:77
本文介绍了如何授予语义释放权限以将代码推送到主站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 semantic-release 自动定义下一个版本,更新 package.json 并推送到 git .但是,我遇到了一个问题,使我无法直接推送到 master .

I'm using semantic-release to automatically define the next version, update package.json and push to git. However, I'm facing a problem where it stop me from direct pushing to 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.

但是我实际上是仓库的所有者,并且已经将 master 的推送权限设置为仅所有者.我是否需要配置任何其他身份验证以使脚本代表我运行?

But I'm actually the owner of the repo and already set push permission for master to only owner. Do i need to config any other authentication for the script to run on my behalf?

所以我的问题是:

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

1/ How to set authentication for semantic-release so that it can push to master directly on your behalf

2/将它直接推送给master是一个好习惯(即使仅用于版本更新).有没有人遇到这种情况,以及您更新版本的解决方案是什么?非常感谢您的投入和想法.

2/ Is it a good practice to direct push to master ( even though its only for version updating). Does anyone experience this scenario and what's your solution to update version. Really Appreciate your input and thoughts.

推荐答案

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

1.In GitLab you have to explicitly set the script to push to Git. For this you need to create a token and pass it to your CI via env variable.

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

In example, see how we do it in our integration project via setting GIT_PUSH_TOKEN - here: https://gitlab.com/taleodor/sample-helm-cd

和此处的实际ci yaml代码:

and the actual ci yaml code here: https://gitlab.com/taleodor/sample-helm-cd/-/blob/master/.gitlab-ci.yml (lines 25-30).

2.是的,直接按下版本凹凸是很常见的.

2.Yes, direct push on version bump is common.

这篇关于如何授予语义释放权限以将代码推送到主站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆