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

Git Authentication issues on Jenkins job #12

Open
Lacront opened this issue Apr 9, 2021 · 4 comments · Fixed by #14
Open

Git Authentication issues on Jenkins job #12

Lacront opened this issue Apr 9, 2021 · 4 comments · Fixed by #14
Assignees
Labels
bug Something isn't working

Comments

@Lacront
Copy link

Lacront commented Apr 9, 2021

Hey, I sadly can't get this plugin to work in my Jenkins environment due to Git authentication errors when the plugin attempts to execute git fetch.
The weird thing is that semantic-release itself has no issues with git.
It can push version commits and set git tags perfectly fine.

Here is my plugin config:

"release": {
    "branches": [
      "master",
      {
        "name": "develop",
        "prerelease": "dev"
      }
    ],
    "plugins": [
      "@semantic-release/commit-analyzer",
      "@semantic-release/release-notes-generator",
      [
        "@semantic-release/npm",
        {
          "npmPublish": false
        }
      ],
      [
        "@semantic-release/git",
        {
          "message": "chore: [RELEASE] Upgrade to ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
        }
      ],
      [
        "@saithodev/semantic-release-backmerge",
        {
          "branchName": "develop",
          "backmergeStrategy": "merge",
          "message": "chore: [RELEASE] Preparations for next release ${nextRelease.version} [skip ci]"
        }
      ]
    ]
  }

Here is my build step:

stage('Create Version') {
  when {
    expression {
      return !noActualChanges
    }
  }
  steps {
    withCredentials([usernameColonPassword(credentialsId: JENKINS_GIT_CREDENTIALS_ID, variable: 'GIT_CREDENTIALS')]) {
      nodejs(JENKINS_NODE_JS_INSTALLATION_LABEL) {
        sh 'npx semantic-release'
      }
    }
    withCredentials([usernamePassword(credentialsId: JENKINS_GIT_CREDENTIALS_ID, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
      sh("git push https://${GIT_USERNAME}:${GIT_PASSWORD}@${GIT_REPO} ${GIT_BRANCH} --tags")
    }
  }
}

And here the error that is thrown:

[5:52:50 PM] [semantic-release] › ✔  Completed step "prepare" of plugin "@semantic-release/npm"
[5:52:50 PM] [semantic-release] › ℹ  Start step "prepare" of plugin "@semantic-release/git"
[5:52:50 PM] [semantic-release] [@semantic-release/git] › ℹ  Found 2 file(s) to commit
[5:52:51 PM] [semantic-release] [@semantic-release/git] › ℹ  Prepared Git release: v1.0.81
[5:52:51 PM] [semantic-release] › ✔  Completed step "prepare" of plugin "@semantic-release/git"
[5:52:51 PM] [semantic-release] › ℹ  Start step "generateNotes" of plugin "@semantic-release/release-notes-generator"
[5:52:51 PM] [semantic-release] › ✔  Completed step "generateNotes" of plugin "@semantic-release/release-notes-generator"
[5:52:53 PM] [semantic-release] › ✔  Created tag v1.0.81
[5:52:53 PM] [semantic-release] › ℹ  Start step "publish" of plugin "@semantic-release/npm"
[5:52:53 PM] [semantic-release] [@semantic-release/npm] › ℹ  Skip publishing to npm registry as npmPublish is false
[5:52:53 PM] [semantic-release] › ✔  Completed step "publish" of plugin "@semantic-release/npm"
[5:52:53 PM] [semantic-release] › ℹ  Start step "success" of plugin "@saithodev/semantic-release-backmerge"
[5:52:53 PM] [semantic-release] [@saithodev/semantic-release-backmerge] › ℹ  Release succeeded. Performing back-merge into branch "develop".
[5:52:53 PM] [semantic-release] › ✖  Failed step "success" of plugin "@saithodev/semantic-release-backmerge"
[5:52:53 PM] [semantic-release] › ✖  An error occurred while running semantic-release: Error: Command failed with exit code 128: git fetch
fatal: Authentication failed for 'https://tasktrack..../bitbucket/scm/ccf/microfrontend-...-next.git/'
    at makeError (/home/jenkins/workspace/microfrontend-...-next CD/node_modules/@saithodev/semantic-release-backmerge/node_modules/execa/lib/error.js:59:11)
    at handlePromise (/home/jenkins/workspace/microfrontend-...-next CD/node_modules/@saithodev/semantic-release-backmerge/node_modules/execa/index.js:114:26)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  shortMessage: 'Command failed with exit code 128: git fetch',
  command: 'git fetch',
  exitCode: 128,
  signal: undefined,
  signalDescription: undefined,
  stdout: '',
  stderr: "fatal: Authentication failed for 'https://tasktrack..../bitbucket/scm/ccf/microfrontend-...-next.git/'",
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false,
  pluginName: '@saithodev/semantic-release-backmerge'
}
AggregateError: 
    Error: Command failed with exit code 128: git fetch
    fatal: Authentication failed for 'https://tasktrack..../bitbucket/scm/ccf/microfrontend-...-next.git/'
        at makeError (/home/jenkins/workspace/microfrontend-...-next CD/node_modules/@saithodev/semantic-release-backmerge/node_modules/execa/lib/error.js:59:11)
        at handlePromise (/home/jenkins/workspace/microfrontend-...-next CD/node_modules/@saithodev/semantic-release-backmerge/node_modules/execa/index.js:114:26)
    at /home/jenkins/workspace/microfrontend-...-next CD/node_modules/�[4msemantic-release�[24m/lib/plugins/pipeline.js:54:11
�[90m    at processTicksAndRejections (internal/process/task_queues.js:97:5)�[39m
    at async Object.pluginsConf.<computed> [as success] (/home/jenkins/workspace/microfrontend-...-next CD/node_modules/�[4msemantic-release�[24m/lib/plugins/index.js:80:11)
    at async run (/home/jenkins/workspace/microfrontend-...-next CD/node_modules/�[4msemantic-release�[24m/index.js:201:3)
    at async module.exports (/home/jenkins/workspace/microfrontend-...-next CD/node_modules/�[4msemantic-release�[24m/index.js:260:22)
    at async module.exports (/home/jenkins/workspace/microfrontend-...-next CD/node_modules/�[4msemantic-release�[24m/cli.js:55:5)

Is the plugin handling git authentication differently than semantic-release?
Thank you!

@Lacront
Copy link
Author

Lacront commented Apr 9, 2021

For those with the same issue.
Here is a workaround for your Jenkinsfile:

        withCredentials([usernamePassword(credentialsId: JENKINS_GIT_CREDENTIALS_ID, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
          sh("git config credential.username ${GIT_USERNAME}")
          sh("git config credential.helper '!f() { echo password=$GIT_PASSWORD; }; f'")
        }
        withCredentials([usernameColonPassword(credentialsId: JENKINS_GIT_CREDENTIALS_ID, variable: 'GIT_CREDENTIALS')]) {
          nodejs(JENKINS_NODE_JS_INSTALLATION_LABEL) {
            sh("npx semantic-release")
          }
        }

@saitho
Copy link
Owner

saitho commented Apr 9, 2021

Hi @Lacront,

Is the plugin handling git authentication differently than semantic-release?

The Git command execution is just the same as semantic-release.
However I noticed that you're using GIT_CREDENTIALS which I didn't know before.
Comparing the Git executions, I noticed that semantic-release uses the repository URL when fetching which I don't.
I'll look into that.

@saitho saitho self-assigned this Apr 9, 2021
saitho added a commit that referenced this issue Apr 9, 2021
Fetch repository with repo URL the same way as semantic-release
does to (hopefully) resolve authentication errors with Jenkins.
@saitho saitho linked a pull request Apr 9, 2021 that will close this issue
@saitho saitho closed this as completed in #14 Apr 9, 2021
saitho added a commit that referenced this issue Apr 9, 2021
Fetch repository with repo URL the same way as semantic-release
does to (hopefully) resolve authentication errors with Jenkins.
@saitho saitho reopened this Apr 9, 2021
@saitho saitho added the bug Something isn't working label Apr 9, 2021
saitho pushed a commit that referenced this issue Apr 9, 2021
## [1.4.1](v1.4.0...v1.4.1) (2021-04-09)

### Bug Fixes

* fetch repository with URL ([#12](#12)) ([2efae25](2efae25))
@saitho
Copy link
Owner

saitho commented Apr 9, 2021

@Lacront

Can you try v1.4.1 to see if that fixed your issue?

saitho added a commit that referenced this issue Apr 12, 2021
This reverts commit 2efae25 as that broke everything.
@saitho
Copy link
Owner

saitho commented Apr 12, 2021

All right, that does not work and breaks the whole execution.
I'll need to setup a Jenkins to propertly debug that.
Going by your workaround, the GIT_USERNAME and GIT_PASSWORD are not set, even though the Git URL should be created with GIT_CREDENTIALS by semantic-release.

@saitho saitho pinned this issue Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants