researchgate / gradle-release

gradle-release is a plugin for providing a Maven-like release process for projects using Gradle
MIT License
867 stars 220 forks source link

initScmAdapter FAILED :Current Git branch is "(HEAD detached at ac857f3)" and not "development". #183

Open inutakki opened 8 years ago

inutakki commented 8 years ago

I am using below: classpath 'net.researchgate:gradle-release:2.3.4' gradle version : gradle-2.11 using different branch than master My configuration for android project is below: apply plugin: 'net.researchgate.release' release { failOnCommitNeeded = true failOnPublishNeeded = true failOnSnapshotDependencies = true failOnUnversionedFiles = true failOnUpdateNeeded = true revertOnFail = true preCommitText = '' preTagCommitMessage = '[Gradle Release Plugin] - pre tag commit: ' tagCommitMessage = 'JenkinsReleaseBuildTag: ' newVersionCommitMessage = '[Gradle Release Plugin] - new version commit: ' //tagging the release using product.release, build.no, and version tagTemplate = "${ant.properties['product.release']}.${ant.properties['build.no']}-${version}" versionPropertyFile = 'gradle.properties' versionProperties = [] buildTasks = ['clean']

  scmAdapters = [
      net.researchgate.release.GitAdapter
  ]

  git {
      requireBranch = 'development'
      pushToRemote = 'origin'

      pushToBranchPrefix = ''
  }

} I am using checkout function to get the application code: checkout ([$class: 'GitSCM', branches: [[name: ""]], userRemoteConfigs: [[credentialsId: "<credentialsId", url: ""]], extensions: [[$class: 'CleanCheckout']]])

I am using below step to invoke release plugin in the code jenkins Integration server sh "${gradleHome}/bin/gradle release -Prelease.useAutomaticVersion=true -Prelease.newVersion=${cdAppProperties.getVersion()}"

11:21:52.433 [ERROR] [org.gradle.BuildExceptionReporter] 11:21:52.435 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception. 11:21:52.435 [ERROR] [org.gradle.BuildExceptionReporter] 11:21:52.435 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong: 11:21:52.435 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':initScmAdapter'. 11:21:52.435 [ERROR] [org.gradle.BuildExceptionReporter] > Current Git branch is "(HEAD detached at 53f373c)" and not "development". 11:21:52.435 [ERROR] [org.gradle.BuildExceptionReporter] 11:21:52.435 [ERROR] [org.gradle.BuildExceptionReporter] * Exception is: 11:21:52.436 [ERROR] [org.gradle.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':initScmAdapter'. 11:21:52.436 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69) 11:21:52.436 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46) 11:21:52.436 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35) 11:21:52.436 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64) 11:21:52.436 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58) 11:21:52.436 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52) 11:21:52.436 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52) 11:21:52.436 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:25) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:110) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher$4.run(DefaultGradleLauncher.java:154) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.Factories$1.create(Factories.java:22) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:52) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:151) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:32) 11:21:52.437 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:99) 11:21:52.438 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:93) 11:21:52.438 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90) 11:21:52.438 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:62) 11:21:52.438 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:93) 11:21:52.438 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:82) 11:21:52.438 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.tasks.GradleBuild.build(GradleBuild.java:117) 11:21:52.438 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75) 11:21:52.438 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:227) 11:21:52.438 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:220) 11:21:52.438 [ERROR] [org.gradle.BuildExceptionReporter] at

Hillkorn commented 8 years ago

Seems that the jenkins doesn't checkout the development branch. It has the revision ac857f3 checked out and tries to run the release task that of course fails because it is not the HEAD of the development branch. Go to the your jenkins project directory and type in "git status" and it will print out

HEAD detached at ac857f3
nothing to commit, working tree clean

if you manage to get the development branch it will work.

nwenz commented 8 years ago

Hello,

I have the same issue. If i'm using the plugin on local build everything works fine. But if I am using the release Task on Jenkins the initSCMAdapter failed. All other Jenkins Jobs works fine with Git.

Hillkorn commented 8 years ago

Jenkins doesn't checkout the branch to test it. It uses the hashes. Could you explain your jenkins workflow please? I try to find a way that fits to it.

Also maybe this helps you? https://issues.jenkins-ci.org/browse/JENKINS-6856

nwenz commented 8 years ago

We have Feature-based git workflow. Everytime a new merge commit on master branch is done our commit Job in Jenkins is triggered. That Job only produces SNAPSHOTs. Another Jenkins Job (listening on master branch) is responsible for the Releases and is triggered manually. This Job is running the release Task and if this step was succesful it runs the publish Task to Nexus.

Do you need more Details?

Hillkorn commented 8 years ago

No that's fine. Maybe this helps you http://stackoverflow.com/questions/11511390/jenkins-git-plugin-detached-head But the problem is that the jenkins checkout is the hash and not the branch. Because of that it is not possible to commit the new version would not be possible and it can't check that branch is up to date to the origin. I mean there are to options now One would be to add a different release flow to the plugin Second is to let the jenkins job checkout the branch instead the hash which i would prefer.

hybaken commented 4 years ago

4 years and still no result? ...

nadarian commented 3 years ago

Adding 'Check out to local branch' solved it for me https://stackoverflow.com/questions/11511390/jenkins-git-plugin-detached-head