Open fpitpit opened 5 years ago
Do you checkout via ssh and on the time gradle executes this it can pull/push? Does it run in a docker container and has no valid .ssh config there?
In general this error does not really seem to be jenkins pipeline related but rather an issue with the git command not working
It does not work with Jenkins pipeline file. I tried running the ./gradlew release command enclosed within sshagent(credentials: ["xxx"]) but no luck.
13:11:30.175 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
13:11:30.175 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.
13:11:30.175 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
13:11:30.175 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
13:11:30.175 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ':jenkins-pipeline-release:preTagCommit'.
13:11:30.176 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Failed to push to remote - [][fatal: remote part of refspec is not a valid name in (HEAD detached at 35aebdd)
Looks to me that it runs on a detached HEAD and therefore can't commit & push. Can you try to checkout a branch with your pipeline instead of a commit?
I tried with explicit git checkout command(sh "_git checkout $GITBRANCH") and it works now.
I do not know how to configure Jenkins declarative pipeline to checkout to a specific branch rather than a detached HEAD(git checkout -f 12f3838aa6).
I added additional stage named checkout and switched to specific branch(git checkout $GIT_BRANCH).
So this plugin do not work with Jenkins pipeline without additional checkout step?
It depends. How is your job triggered? Do you create releases manually or for every build?
seenimurugan notifications@github.com schrieb am Di., 26. Feb. 2019, 16:13:
I tried with explicit git checkout command and it works now. I do not know how to configure Jenkins declarative pipeline to checkout to a specific branch rather than a detached HEAD(git checkout -f 12f3838aa6). I added additional stage named checkout and switched to specific branch(git checkout develop). So this plugin do not work with Jenkins pipeline without additional checkout step?
— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/researchgate/gradle-release/issues/282#issuecomment-467476630, or mute the thread https://github.com/notifications/unsubscribe-auth/ABsepJGQINaAISC5M8M1nH13TLIByGNNks5vRU7_gaJpZM4aQcmA .
I also have this problem right now. I want to use this plugin, but when Jenkins checks out the source code it uses a "detached HEAD" instead of the release branch as I expected. I'm at a loss of how to fix this. The work around that @seenimurugans mentioned could work, but why can't Jenkin's just use the release branch! I'll keep looking, but @seenimurugans let me know if you find a better way to make this work.
What I tried:
Output from Jenkin's Console:
Started by user Craig Moore
> git rev-parse --is-inside-work-tree # timeout=10
Setting origin to https://company.repo/scm/bitbucket/iproto/aptng.git
> git config remote.origin.url https://company.repo/scm/bitbucket/iproto/aptng.git # timeout=10
Fetching origin...
Fetching upstream changes from origin
> git --version # timeout=10
> git config --get remote.origin.url # timeout=10
using GIT_ASKPASS to set credentials My git repo username and password
> git fetch --tags --progress origin +refs/heads/*:refs/remotes/origin/*
Seen branch in repository origin/dragon
Seen 1 remote branch
Obtained db/jenkins/Jenkinsfile from a11b13f7f4b197bbbdc84b46e8bf46d0b74ef468
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Workstation in /tmp/jenkins_slave/workspace/WSI_DB_dragon
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
using credential aptng
Fetching changes from the remote Git repository
Fetching without tags
Checking out Revision a11b13f7f4b197bbbdc84b46e8bf46d0b74ef468 (dragon)
Commit message: "fix/db - Fix the release stage - Jenkinsfile: fix the shebang, remove the explicit 'git checkout dragon' it should be dragon branch!"
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
> git rev-parse --is-inside-work-tree # timeout=10
> git config remote.origin.url https://company.repo/scm/bitbucket/iproto/aptng.git # timeout=10
Fetching upstream changes from https://company.repo/scm/bitbucket/iproto/aptng.git
> git --version # timeout=10
using GIT_ASKPASS to set credentials My git repo username and password
> git fetch --no-tags --progress https://company.repo/scm/bitbucket/iproto/aptng.git +refs/heads/*:refs/remotes/origin/*
> git config core.sparsecheckout # timeout=10
> git checkout -f a11b13f7f4b197bbbdc84b46e8bf46d0b74ef468
> git rev-list --no-walk 2b6c417979200244f937172d0ed425785d1c8076 # timeout=10
...
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Release)
[Pipeline] sh
+ cd db
+ gradle release
> Task :db:createScmAdapter
> Task :db:initScmAdapter FAILED
> Task :release FAILED
Release process failed, reverting back any changes made by Release Plugin.
Running [git, checkout, gradle.properties] produced an error: [error: pathspec 'gradle.properties' did not match any file(s) known to git.]
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':db:initScmAdapter'.
> Current Git branch is "(HEAD detached at a11b13f)" and not "dragon".
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
1 actionable task: 1 executed
I added additional stage named checkout and switched to specific branch(git checkout $GIT_BRANCH).
How were you able to pass the git credentials for checkout?
@craigtmoore You can try to add additional behavior to your Jenkins configuration. Your multibranch pipeline -> Configure -> Git -> Behaviours -> Add -> Check out to matching local branch. This worked for me.
@Bragrel Hm.... that seems to have gotten past the 'HEAD detached at a11...', but now its asking for credentials again:
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Release)
[Pipeline] sh
+ cd db
+ gradle release
> Task :db:createScmAdapter
> Task :db:initScmAdapter
> Task :db:checkCommitNeeded
> Task :db:checkUpdateNeeded FAILED
Running [git, remote, update] produced an error: [fatal: could not read Username for 'https://company.repo': No such device or address
error: Could not fetch origin]
> Task :release FAILED
Release process failed, reverting back any changes made by Release Plugin.
Running [git, checkout, gradle.properties] produced an error: [error: pathspec 'gradle.properties' did not match any file(s) known to git.]
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':db:checkUpdateNeeded'.
> Failed to run [git remote update] - [Fetching origin
][fatal: could not read Username for 'https://company.repo': No such device or address
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. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
1 actionable task: 1 executed
@craigtmoore I've added Jenkins' ssh-key to GitHub and using git@github.com:xxx/yyy.git format.
Ah, I suppose I should use an ssh (rather than http) git url for it and use the keys so it doesn't prompt me for silly passwords. Thanks!
Awsome, I got it to work. Thanks for your help Bragrel. For others, I followed this blog to generate the ssh keys, and add them to my gitrepo and to Jenkins: https://mohitgoyal.co/2017/02/27/configuring-ssh-authentication-between-github-and-jenkins/ After that, I selected them under the project's GIT settings.
I also forgot to include the '-Prelease.useAutomaticVersion=true' along with the gradle release so don't forget about that.
Can this work with just https not having to switch to ssh as git token in used
For those having trouble with Jenkins Pipeline.. I'm using Git Checkout via HTTPS, by adding the following additional Git Checkout property (Check out to matching local branch) would fix HEAD detached issue
The error that I initially have before setting the property: [2023-07-26T13:33:36.156Z] > Task :myProject-release:preTagCommit FAILED [2023-07-26T13:33:36.156Z] Running [git, push, --porcelain, origin, (HEAD detached from 1234e56dc4)] produced an error: [fatal: invalid refspec '(HEAD detached from 1234e56dc4)']
When i launch ./gradlew release in stage into jenkinsFile, I've got error message on pretagCommit task 👍