JGit:通过Jenkins在推送时获取异常(TransportException:无需推送)

时间:2018-07-12 09:47:05

标签: java git jenkins egit jgit

下面的代码在本地运行时工作正常,但是通过jenkins运行相同的代码时会抛出异常。

Git git = Git.open(gitWorkDir);
                Repository repo = git.getRepository();
                log.info(repo.getDirectory().getPath());

                String userName = envProperties.getString("username");
                String password = envProperties.getString("password");
                UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider(userName, password);
                PullResult result = git.pull().setCredentialsProvider(user).setRemote("origin")
                        .setRemoteBranchName("master").call();
                if (result.isSuccessful()) {
                        git.add().addFilepattern(Constant.LABEL_API_PROJECT_NAME + Constant.SKINS_PATH).call();

                    ObjectId lastCommitId = repo.resolve(Constants.HEAD);
                    revWalk = new RevWalk(repo);
                    RevCommit commit = revWalk.parseCommit(lastCommitId);
                    log.info(commit.getAuthorIdent());
                    git.commit().setMessage("Message").call();
                    git.push().setCredentialsProvider(user).call();
Cause: org.eclipse.jgit.api.errors.TransportException: Nothing to push.
    org.eclipse.jgit.api.errors.TransportException: Nothing to push.
        at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:180)
        at com.bold.api.portalskin.UpdateBaselineSkins.commitpullGit(UpdateBaselineSkins.java:100)
        at com.bold.api.portalskin.UpdateBaselineSkins.updateBaselineSkins(UpdateBaselineSkins.java:47)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
        at org.testng.TestRunner.privateRun(TestRunner.java:744)
        at org.testng.TestRunner.run(TestRunner.java:602)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
        at org.testng.SuiteRunner.run(SuiteRunner.java:289)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
        at org.testng.TestNG.runSuites(TestNG.java:1144)
        at org.testng.TestNG.run(TestNG.java:1115)
        at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:283)
        at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75)
        at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:120)
        at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:386)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:323)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:143)
    Caused by: org.eclipse.jgit.errors.TransportException: Nothing to push.
        at org.eclipse.jgit.transport.Transport.push(Transport.java:1334)
        at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:170)

从jenkins运行相同的代码时获取此异常,但是当我在本地计算机上运行时,此代码工作正常

0 个答案:

没有答案