Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When multiple git credentials are available in environment, the first one is used regardless of the others #1668

Closed
arcln opened this issue Oct 28, 2020 · 1 comment

Comments

@arcln
Copy link
Contributor

arcln commented Oct 28, 2020

Current behavior

If both GITHUB_TOKEN and GITLAB_TOKEN are defined in the environment, semantic-release will use GITHUB_TOKEN to authenticate, even if the repository is hosted on Gitlab.

This is due to get-git-auth-url that stops on the first available token (using the order defined in lib/get-git-auth-url.js:19).

This is most probably what is causing #1484.
I propose a fix in #1669.

Expected behavior

Semantic release should look for all tokens and use the one that actually works.

Environment

  • semantic-release version: 17.2.1, master
  • CI environment: any
  • Plugins used: not relevant
  • semantic-release configuration:
{
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    [
      "@semantic-release/gitlab",
      { "gitlabUrl": "https://gitlab.example.com" }
    ]
  ]
}
  • CI logs:
$ echo GITHUB_TOKEN
[MASKED]
$ echo GITLAB_TOKEN
[MASKED]
$ git push --dry-run "https://gitlab-ci-token:$GITLAB_TOKEN@gitlab.example.com/group/repo.git" HEAD:master
Everything up-to-date
$ semantic-release --ci --debug
[12:23:39 PM] [semantic-release] › ℹ  Running semantic-release version 17.2.1
2020-10-27T12:23:39.657Z semantic-release:config load config from: /builds/group/repo/.releaserc.json
2020-10-27T12:23:39.675Z semantic-release:config options values: { branches:
   [ '+([0-9])?(.{+([0-9]),x}).x',
     'master',
     'next',
     'next-major',
     { name: 'beta', prerelease: true },
     { name: 'alpha', prerelease: true } ],
  repositoryUrl:
   'https://gitlab-ci-token:[secure]@gitlab.example.com/group/repo.git',
  tagFormat: 'v${version}',
  plugins:
   [ '@semantic-release/commit-analyzer',
     '@semantic-release/release-notes-generator',
     [ '@semantic-release/gitlab', [Object] ] ],
  _: [],
  ci: true,
  debug: true,
  '$0': '/usr/local/bin/semantic-release' }
2020-10-27T12:23:40.080Z semantic-release:plugins options for @semantic-release/gitlab/verifyConditions: { gitlabUrl: 'https://gitlab.example.com' }
[12:23:40 PM] [semantic-release] › ✔  Loaded plugin "verifyConditions" from "@semantic-release/gitlab"
2020-10-27T12:23:40.082Z semantic-release:plugins options for @semantic-release/commit-analyzer/analyzeCommits: {}
[12:23:40 PM] [semantic-release] › ✔  Loaded plugin "analyzeCommits" from "@semantic-release/commit-analyzer"
2020-10-27T12:23:40.084Z semantic-release:plugins options for @semantic-release/release-notes-generator/generateNotes: {}
[12:23:40 PM] [semantic-release] › ✔  Loaded plugin "generateNotes" from "@semantic-release/release-notes-generator"
2020-10-27T12:23:40.084Z semantic-release:plugins options for @semantic-release/gitlab/publish: { gitlabUrl: 'https://gitlab.example.com' }
[12:23:40 PM] [semantic-release] › ✔  Loaded plugin "publish" from "@semantic-release/gitlab"

# -----> HERE semantic release actually tries to authenticate using the `GITHUB_TOKEN`, which explains the failure
2020-10-27T12:23:40.115Z semantic-release:get-git-auth-url Verifying ssh auth by attempting to push to  https://gitlab-ci-token:[secure]@gitlab.example.com/group/repo.git
2020-10-27T12:23:40.291Z semantic-release:git Error: Command failed with exit code 128: git push --dry-run --no-verify https://gitlab-ci-token:[secure]@gitlab.example.com/group/repo.git HEAD:master
remote: You are not allowed to upload code.
fatal: unable to access 'https://gitlab.example.com/group/repo.git/': The requested URL returned error: 403
    at makeError (/usr/local/lib/node_modules/semantic-release/node_modules/execa/lib/error.js:59:11)
    at handlePromise (/usr/local/lib/node_modules/semantic-release/node_modules/execa/index.js:114:26)
    at process._tickCallback (internal/process/next_tick.js:68:7)
2020-10-27T12:23:40.291Z semantic-release:get-git-auth-url SSH key auth failed, falling back to https.
[12:23:40 PM] [semantic-release] › ✖  An error occurred while running semantic-release: { Error: Command failed with exit code 128: git ls-remote --heads https://[secure]@gitlab.example.com/group/repo.git
remote: HTTP Basic: Access denied
fatal: Authentication failed for 'https://gitlab.example.com/group/repo.git/'
    at makeError (/usr/local/lib/node_modules/semantic-release/node_modules/execa/lib/error.js:59:11)
    at handlePromise (/usr/local/lib/node_modules/semantic-release/node_modules/execa/index.js:114:26)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  shortMessage:
   'Command failed with exit code 128: git ls-remote --heads https://[secure]@gitlab.example.com/group/repo.git',
  command:
   'git ls-remote --heads https://[secure]@gitlab.example.com/group/repo.git',
  exitCode: 128,
  signal: undefined,
  signalDescription: undefined,
  stdout: '',
  stderr:
   'remote: HTTP Basic: Access denied\nfatal: Authentication failed for \'https://gitlab.example.com/group/repo.git/\'',
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false }
{ Error: Command failed with exit code 128: git ls-remote --heads https://[secure]@gitlab.example.com/group/repo.git
remote: HTTP Basic: Access denied
[...]
@arcln
Copy link
Contributor Author

arcln commented Oct 29, 2020

solved in v17.2.2

@arcln arcln closed this as completed Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant