使用Gradle Release Plugin

时间:2018-03-13 16:19:48

标签: git jenkins ssh gradle-release-plugin

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

2 个答案:

答案 0 :(得分:1)

  

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

然后Jenkins也应该提供:

  • 使用相同的用户执行
  • ,SSH密钥是默认的〜/ .ssh / id_rsa。

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

答案 1 :(得分:0)

使用ssh代理包装评分电话:

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

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