gitlabgitlab-cigitlab-apisemantic-release

Semantic release not accepting GITLAB_TOKEN on gitlab private repository


Here is the error log message:

[3:40:55 PM] [semantic-release] › ✖ The command "git push --dry-run --no-verify https://gitlab-ci-token:[secure]@[repository-url].git HEAD:main" failed with the error message remote: You are not allowed to upload code. fatal: unable to access 'https://gitlab-ci-token:[secure]@[repository-url]/': The requested URL returned error: 403.

I have a GITLAB_TOKEN set up in the repository settings with all the necessary permissions, but it seems it isn't even being used:

enter image description here

Here is my .releaserc.json config:

{
  "branches": ["main", { "name": "beta", "prerelease": true }],
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/changelog",
    "@semantic-release/npm",
    "@semantic-release/gitlab",
    [
      "@semantic-release/git",
      {
        "assets": ["package.json", "package-lock.json", "CHANGELOG.md"],
        "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
      }
    ]
  ]
}

Here it's my .gitlab-ci.yml config:

# NodeJs image
image: node:16

# STAGES
stages:
  - checks
  - build
  - release

# SETUP
before_script:
  - node -v
  - npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
  - npm ci --cache .npm --prefer-offline

# JOBS
lint:
  stage: checks
  script:
    - npm run lint

test:
  stage: checks
  script:
    - npm run test:ci

build:
  stage: build
  script:
    - npm run build

release:
  stage: release
  only:
    - main
  script:
    - npx semantic-release

And here are the semantic release dependencies I'm using and it's versions:

"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@semantic-release/gitlab": "^7.0.4",
"@semantic-release": "^19.0.2",

The GITLAB_TOKEN is a member of the repository as a maintainer (just like the other repositories where semantic release is working):

enter image description here

Any suggestions?


Solution

  • So in the end the problem was that I had to add the created GITLAB_TOKEN access token in Settings > CI/CD > Variables