Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grgit fails on teamcity #221

Closed
SchwiftyRick opened this issue Apr 4, 2018 · 7 comments
Closed

grgit fails on teamcity #221

SchwiftyRick opened this issue Apr 4, 2018 · 7 comments

Comments

@SchwiftyRick
Copy link

SchwiftyRick commented Apr 4, 2018

Hi Andrew, I have build a versioning script. It has to switch between two branches (gradleVersioning and feature/gradle). The script has to checkout and push these branches. Running it locally works as designed. On teamcity push fails silently and after second checkout grgit does not recognize changes in my propertiy files.
my task dependencies:

build.finalizedBy artifactoryPublish
artifactoryPublish.finalizedBy updateDev
updateDev.dependsOn gitCommitToMaster

task gitCommitToMaster should commit and push changes made prior in the build:

task gitCommitToMaster {
    group 'gradleVersioning'
    description 'checks out dev branch and commits the new version (-SNAPSHOT cut off) in .s2i and gradle.properties'
    doLast {
        grgit = Grgit.open(dir: '.')

        grgit.checkout(branch: 'origin/gradleVersioning', createBranch: false)
        grgit.add(patterns: ['gradle.properties', '.s2i/bin'])

        grgit.commit {
            message = 'automated Gradle Commit'
            all = false
        }
        grgit.tag.add(name: "V${version}")
        grgit.push(remote: 'origin', refsOrSpecs: ['gradleVersioning'], tags: true)
        grgit.fetch()
        grgit.pull(remote: 'origin', branch: 'gradleVersioning')
        //grgit.reset(mode: 'hard', commit: 'origin/gradleVersioning')
        grgit.close()
        println "gitCommitToMaster successful"
    }

}

task updateDev does change the version and then also commits/pushes

task updateDev {
    group 'gradleVersioning'
    description 'increments the version number and writes it to local project'
    doLast {
        grgit = Grgit.open(dir: '.')
        //grgit.fetch(refSpecs: ['refs/remotes/feature/gradle'])

        grgit.checkout(branch: 'origin/feature/gradle', createBranch: false)
        //grgit.pull(remote: 'origin', branch: 'feature/gradle')
        versionMap['Minor'] = (versionMap['Minor'] as Integer) + 1
        versionMap['Patch'] = 0
        /*This task will be extended when we switch from basic to semantic versioning*/
        def newVersion = "${versionMap['Major']}.${versionMap['Minor']}.${versionMap['Patch']}-SNAPSHOT"
        println "incremented version for Dev branch: ${newVersion}"
        try {
            writeToProperties.call(newVersion, "gradle.properties")
            writeToProperties.call(newVersion, ".s2i/bin/assemble")
            println 'writing new version to working directory -> successful'
        }
        catch (IOException ex) {
            println "gradle.properties in root is not found or locked"
        }
        println "start git add, commit and push to DevBranch"
        grgit.add(patterns: ['gradle.properties', '.s2i/bin'])
        grgit.commit {
            message = 'automated Gradle commit for version update'
            all = false
        }
        grgit.push(remote: 'origin', refsOrSpecs: ['feature/gradle'])
        grgit.reset(mode: 'hard', commit: "origin/feature/gradle")
        grgit.close()
        println "-> was successful"

    }

}

errorlog:

gitCommitToMaster (1s)
[13:44:14]gitCommitToMaster successful
[13:44:14]:updateDev
[13:44:14]incremented version for Dev branch: 3.1338.0-SNAPSHOT
[13:44:14]write to gradle.properties successful
[13:44:14]write to gradle.properties successful
[13:44:14]writing new version to working directory -> successful
[13:44:14]start git add, commit and push to DevBranch
[13:44:14]
[13:44:14]
[13:44:14]BUILD FAILED
[13:44:14]
[13:44:14]Total time: 1 mins 16.886 secs
[13:44:14]##teamcity[buildProblem identity='-398317399' description='Execution failed for task |':updateDev|'. org.eclipse.jgit.api.errors.TransportException: Nothing to push.' type='gradleBuildProblem']
[13:44:15]Process exited with code 1
[13:44:15]Gradle failure report
[13:44:15]FAILURE: Build failed with an exception.
[13:44:15]
[13:44:15]* Where:
[13:44:15]Build file '/home/tcagent/buildAgent/work/9630fb096086b628/build.gradle' line: 293
[13:44:15]
[13:44:15]* What went wrong:
[13:44:15]Execution failed for task ':updateDev'.
[13:44:15]> Nothing to push.
[13:44:15]
[13:44:15]* Try:
[13:44:15]Run with --info or --debug option to get more log output.
[13:44:15]
[13:44:15]* Exception is:
[13:44:15]org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':updateDev'.
[13:44:15]	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:84)
[13:44:15]	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:55)
[13:44:15]	at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
[13:44:15]	at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
[13:44:15]	at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
[13:44:15]	at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:46)
[13:44:15]	at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
[13:44:15]	at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
[13:44:15]	at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
[13:44:15]	at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
[13:44:15]	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:236)
[13:44:15]	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:228)
[13:44:15]	at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
[13:44:15]	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
[13:44:15]	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
[13:44:15]	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:228)
[13:44:15]	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215)
[13:44:15]	at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:77)
[13:44:15]	at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:58)
[13:44:15]	at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:32)
[13:44:15]	at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:113)
[13:44:15]	at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
[13:44:15]	at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
[13:44:15]	at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
[13:44:15]	at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
[13:44:15]	at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
[13:44:15]	at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
[13:44:15]	at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
[13:44:15]	at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:196)
[13:44:15]	at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:193)
[13:44:15]	at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
[13:44:15]	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
[13:44:15]	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
[13:44:15]	at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:193)
[13:44:15]	at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:119)
[13:44:15]	at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:102)
[13:44:15]	at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:71)
[13:44:15]	at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
[13:44:15]	at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
[13:44:15]	at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
[13:44:15]	at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
[13:44:15]	at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
[13:44:15]	at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
[13:44:15]	at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:44)
[13:44:15]	at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:29)
[13:44:15]	at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:51)
[13:44:15]	at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:173)
[13:44:15]	at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:244)
[13:44:15]	at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:217)
[13:44:15]	at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:33)
[13:44:15]	at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
[13:44:15]	at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
[13:44:15]	at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
[13:44:15]	at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:210)
[13:44:15]	at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:174)
[13:44:15]	at org.gradle.launcher.Main.doAction(Main.java:33)
[13:44:15]	at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
[13:44:15]	at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:60)
[13:44:15]	at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:37)
[13:44:15]	at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
[13:44:15]	at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:31)
[13:44:15]	at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:108)
[13:44:15]	at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
[13:44:15]Caused by: org.eclipse.jgit.api.errors.TransportException: Nothing to push.
[13:44:15]	at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:180)
[13:44:15]	at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:85)
[13:44:15]	at java_util_concurrent_Callable$call$0.call(Unknown Source)
[13:44:15]	at org.ajoberstar.grgit.operation.PushOp.call(PushOp.groovy:85)
[13:44:15]	at org.ajoberstar.grgit.operation.PushOp.call(PushOp.groovy)
[13:44:15]	at java_util_concurrent_Callable$call.call(Unknown Source)
[13:44:15]	at java_util_concurrent_Callable$call.call(Unknown Source)
[13:44:15]	at org.ajoberstar.grgit.internal.OpSyntax.mapOperation(OpSyntax.groovy:33)
[13:44:15]	at org.ajoberstar.grgit.internal.OpSyntax$mapOperation.callStatic(Unknown Source)
[13:44:15]	at org.ajoberstar.grgit.Grgit.push(Grgit.groovy)
[13:44:15]	at org.ajoberstar.grgit.Grgit$push$4.call(Unknown Source)
[13:44:15]	at build_4vt9fauifmm8g0g715qp7omw0$_run_closure17$_closure35.doCall(/home/tcagent/buildAgent/work/9630fb096086b628/build.gradle:293)
[13:44:15]	at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:596)
[13:44:15]	at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:577)
[13:44:15]	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:95)
[13:44:15]	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:76)
[13:44:15]	... 62 more
[13:44:15]Caused by: org.eclipse.jgit.errors.TransportException: Nothing to push.
[13:44:15]	at org.eclipse.jgit.transport.Transport.push(Transport.java:1332)
[13:44:15]	at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:169)
[13:44:15]	... 77 more
@ajoberstar
Copy link
Owner

I'm having trouble following what your intended behavior is for these tasks, but here are a few things that look off to me:

  1. Checking out any origin/* branch (e.g. origin/gradleVersioning) is not typically what you would want. Through CLI git, this results in a detached HEAD state rather than being on a branch named gradleVersioning that tracks origin/gradleVersioning. I assume the same is true from grgit.
  2. If you push the gradleVersioning ref it would push the refs/heads/gradleVersioning to the remote equivalent of refs/remotes/origin/gradleVersioning. Since you checked out a detached HEAD, I don't think you made a commit on that branch, so I'm not sure what is getting pushed in that case.
  3. Once you've done the push, the fetch and pull should be unnecessary as well. You would have to be up to date already, because the push would fail if you weren't.

Similar things seem to be going on in the update task. It's possible you encounter a failure in TeamCity because you have different branches in your local repo than TeamCity has. Resolving some of the things above might get you where you need to go.

@ajoberstar
Copy link
Owner

Feel free to reopen.

@SchwiftyRick
Copy link
Author

SchwiftyRick commented Apr 17, 2018

So lets look at task gitCommitToMaster:

task gitCommitToMaster {
    group 'gradleVersioning'
    description 'checks out dev branch and commits the new version (-SNAPSHOT cut off) in .s2i and gradle.properties'
    doLast {
        Credentials creds= new Credentials("$bitbucketUser","$bitbucketPass")
        grgit = Grgit.open(dir: '.',creds: creds)
        grgit.checkout(branch: 'gradleVersioning', createBranch: false)
        grgit.add(patterns: ['gradle.properties', '.s2i/bin'])
        grgit.commit {
            message = 'automated Gradle Commit'
            all = false
        }
        grgit.tag.add(name: "V${version}")
        grgit.push(tags: true)
        grgit.close()
        println "gitCommitToMaster successful"

    }

}

Still fails silently.
When i list all branches on the buildsever, it just shows gradleversioning-local and -remote, even though I have many more.

@ajoberstar ajoberstar reopened this Apr 17, 2018
@ajoberstar
Copy link
Owner

I wonder if you're running in to #216? Do you have any hooks turned on within Bitbucket? If so, are there any logs for those that would show whether they're failing or not?

As for the branch list not showing everything, do you know if TeamCity clones all of the branches? I know some CI systems won't do that by default.

@ajoberstar
Copy link
Owner

2.2.0-rc.1 has a fix to throw an exception for declined/rejected push. You may want to give that a try in case it is tied to your issue.

@SchwiftyRick
Copy link
Author

Regarding the first issue you were right. It was indeed due to a pre-recieve webhook.
I added task:
task pushToGit(type: Exec) {

workingDir '.'
commandLine 'git', 'push', 'origin', 'gradleVersioning'

}

which then showed me a 401 in the log.
Unfortunately, your new version is not in our artifactory but will give it a try at home.
Thank you

@ajoberstar
Copy link
Owner

Sounds good, let me know if the second issue is still happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants