I am using BitBucket and I have created a plugin to automatically tag the branch based on some information. Things are working nicely in my local machine and push to remote repository works fine, however, when we push the changes into Bitbucket Pipeline (that builds the project using maven) it push fails with the following error:
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
From my understanding, the username you can see in the error log is being picked from the local git files in the server as the build process checks out the branch to compile it:
git@bitbucket.org
And it seems it ignores my configured credentials. This is the code I am using to push the changes (The code in GitUtil in the error log):
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();
Have I missed anything here? Why is it ignoring the credentials? If I have to set the remote branch and url, how do I get it with JGit, there should be somewhere in the configuration?