frinux frinux - 9 months ago 114
Git Question

Jenkins Pipelines with Gradle release plugin

I'm using Jenkins Pipelines to build my packages and deliver them to Artifactory. I'm trying to use it with Gradle, through the Gradle Release Plugin, but there's something wrong with it.

I'm starting a ssh-agent so that Gradle has the permission to push on Git repository:

sshagent([git_credential]) {
sh "./gradlew clean release unSnapshotVersion -Prelease.useAutomaticVersion=true -Prelease.releaseVersion=${release_version} -Prelease.newVersion=${development_version}"

The problem is Gradle seems to run asynchronously, the ssh-agent stops before the end of Gradle execution. See the Jenkins log above:

[Pipeline] sshagent
[ssh-agent] Using credentials git
[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent] Java/JNR ssh-agent
[ssh-agent] Registered BouncyCastle on the remote agent
[ssh-agent] Started.
[Pipeline] {
[Pipeline] sh
[Release - MyModule] Running shell script
+ ./gradlew clean release unSnapshotVersion -Prelease.useAutomaticVersion=true -Prelease.releaseVersion=1.1.0 -Prelease.newVersion=1.2.0-SNAPSHOT
:Release - MyModule:createScmAdapter
:Release - MyModule:initScmAdapter
:Release - MyModule:checkCommitNeeded
[ssh-agent] Stopped.
:Release - MyModule:checkUpdateNeeded
Running [git, remote, update] produced an error: [fatal: could not read Username for '': No such device or address
error: Impossible de récupérer origin]
:Release - MyModule:checkUpdateNeeded FAILED
:release FAILED
Release process failed, reverting back any changes made by Release Plugin.

Is it possible to force Gradle to run synchronously?


Answer Source

The logs misleaded me, ssh-agent was exiting because Gradle had no access to GIT repository. In fact, in was cloning a Bitbucket repo using https, which needs user+pwd. When cloning the same repo using SSH, the ssh-agent provides the certificates and Gradle is able to communicate with Bitbucket.