【问题标题】:SSH Git access using Gradle Release Plugin使用 Gradle 发布插件的 SSH Git 访问
【发布时间】:2018-03-13 16:19:48
【问题描述】:

使用 Jenkins Pipeline 我将存储库 URL 从 http 更改为 ssh git 访问。 这样做之后,这项工作就不再工作了(在此之前一切正常)。

在日志下方:

: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

SSH RSA 密钥工作正常,因为: - 我在我们的 Bitbucket 服务器上正确配置,以便在该 repo 上读/写 - 我将密钥添加到 ssh-agent - 我可以直接从执行 jenkins 作业的服务器克隆和提交。

这是 gradle 构建文件部分:

....
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]
}
....

【问题讨论】:

  • 而 gradle 在 jenkins 中是由同一个用户执行的?

标签: git jenkins ssh gradle-release-plugin


【解决方案1】:

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

那么 Jenkins 也应该这样做,前提是:

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

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

【讨论】:

  • 非常感谢@VonC,将 SSH 密钥更改为默认密钥后,现在可以正常工作了。
【解决方案2】:

使用 ssh 代理包装对评分的调用:

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

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

【讨论】:

    猜你喜欢
    • 2014-07-23
    • 1970-01-01
    • 1970-01-01
    • 2015-02-27
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多