5

Using Jenkins Pipeline I changed the Repository URL from http to ssh git access. After doing that the job is not working anymore (before that all worked correctly).

Down below the logs:

:xxxxxx:checkUpdateNeeded
Running [git, remote, update] produced an error: [Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
error: Could not fetch origin]
:xxxxxx:checkUpdateNeeded FAILED
:release FAILED
Release process failed, reverting back any changes made by Release Plugin.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':checkUpdateNeeded'.
> Failed to run [git remote update] - [Fetching origin
  ][Permission denied (publickey).
  fatal: Could not read from remote repository.

  Please make sure you have the correct access rights
  and the repository exists.
  error: Could not fetch origin
  ]

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

The SSH RSA Key is correctly working because: - I configured correctly on our Bitbucket server in order to Read/Write on that repo - I added the key into ssh-agent - I can clone and commit directly from the server where the jenkins job is executed.

This is the gradle build file section:

....
release {
    versionPropertyFile="${rootDir}/gradle.properties"
    failOnCommitNeeded=false
    git{
        requireBranch="releases/.*|master"
    }
    tagTemplate = 'T-'+new Date().format('yy.MM')+'-${version}'
}


task publishRelease(type: GradleBuild) {
    tasks = ['publishMavenJavaPublicationToReleaseRepository']
    startParameter.projectProperties = [nexusUser: nexusUser, nexusPassword: nexusPassword]
}
....
4

2 回答 2

1

我可以直接从执行 jenkins 作业的服务器克隆和提交。

然后詹金斯也应该,提供:

  • 它由同一个用户执行
  • SSH 密钥是默认的 ~/.ssh/id_rsa。

如果不满足这两个条件中的任何一个,您需要使用Jenkins SSH Credentials Plugin指定私钥的确切路径。

于 2018-03-14T05:55:48.567 回答
0

使用 ssh 代理包装对等级的调用:

sshagent(credentials: ['id-of-private-key-defined-in-jenkins']) {
   withGradle {
     sh 'gradle release -Prelease.useAutomaticVersion=true'
   }
}

这将使私钥可用于下面的 Git 调用。

于 2020-09-02T13:35:45.493 回答