我正在使用BitBucket,我已经创建了一个插件,可以根据一些信息自动标记分支。事情在我的本地机器上很好地工作并且推送到远程存储库工作正常,但是,当我们将更改推送到Bitbucket Pipeline(使用maven构建项目)时,它推送失败并出现以下错误:
org.eclipse.jgit.api.errors.TransportException: git@bitbucket.org:testrepo/test-tagging.git: Auth fail
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:165)
at com.mytest.semver.utils.GitUtils.push(GitUtils.java:150)
at com.mytest.semver.utils.GitUtils.commitAndPush(GitUtils.java:232)
at com.mytest.semver.maven.plugin.TagMojo.execute(TagMojo.java:231)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
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.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.eclipse.jgit.errors.TransportException: git@bitbucket.org:testrepo/test-tagging.git: Auth fail
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:159)
at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:137)
at org.eclipse.jgit.transport.TransportGitSsh$SshPushConnection.<init>(TransportGitSsh.java:322)
at org.eclipse.jgit.transport.TransportGitSsh.openPush(TransportGitSsh.java:167)
at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:155)
at org.eclipse.jgit.transport.Transport.push(Transport.java:1250)
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:157)
... 25 more
Caused by: com.jcraft.jsch.JSchException: Auth fail
at com.jcraft.jsch.Session.connect(Session.java:512)
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:116)
... 31 more
根据我的理解,您可以从服务器中的本地git文件中选择您可以在错误日志中看到的用户名,因为构建过程会检出分支以进行编译:
git@bitbucket.org
它似乎忽略了我配置的凭据。这是我用来推送更改的代码(错误日志中GitUtil中的代码):
Git git = Git.open(Paths.get("")); // This will select the current directory
CredentialsProvider cr = new UsernamePasswordCredentialsProvider("my_username", "my_pass");
RefSpec spec = new RefSpec("refs/remotes/origin/develop"); //we only tag this branch
Iterable<PushResult> rev = git.push()
.setPushTags()
.setRefSpecs(spec)
.setCredentialsProvider(cr)
.call();
我在这里错过了什么吗?为什么忽略凭证?如果我必须设置远程分支和URL,我如何使用JGit获取它,配置中应该有什么地方?