It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to use maven release plugin with bitbucket pipelines? Edited

How do I get the maven release plugin to work with bitbucket pipelines?

Our pipeline is utilizing BITBUCKET_GIT_HTTP_ORIGIN for the configuration of the release with the following steps:

mvn -B release:prepare
mvn -B release:perform

mvn release:prepare works correctly and updates versions and commits it back to origin. However, the release:perform step fails with the following error:

[ERROR] Cloning into '/opt/atlassian/pipelines/agent/build/target/checkout'...
[ERROR] fatal: could not read Username for 'https://bitbucket.org': No such device or address

 The clone command it is trying to run:

[INFO] Executing: /bin/sh -c cd /opt/atlassian/pipelines/agent/build/target && git clone --branch v1.0.8 <private-project-url-removed> /opt/atlassian/pipelines/agent/build/target/checkout

The url that it is using is the same from the other bitbucket commands that were executed from the release:prepare step. 

 

1 answer

0 votes

Hi Zachary,

Are you sure the url is identical? In particular, check to make sure that it is a "http" url and not a "https" url. Git operations against origin go via a local proxy (running alongside your build container and only accessible to your build) and if you look at the value of BITBUCKET_GIT_HTTP_ORIGIN you'll see that it uses the plain, unsecured "http" protocol. The proxy establishes a secure "https" connection when it talks to the real server.

(This all assumes that you're connecting to the origin server of your main repository, which it seems like you are doing. If I've misunderstood and you're actually trying to connect to another repository or another server then that connection won't be using the local proxy. It should use a secure protocol and it will require that you set up authentication manually).

Yes I am sure it's using http. Like I said, the 'prepare' phase is working correctly which pushes commits back to the original repo.

Our team will be moving away from bitbucket for our CI solution. We have spent too much time already trying to get around the bugs.

You should use the exactly url show in BITBUCKET_GIT_HTTP_ORIGIN, example

http://bitbucket/[user]/[project]

NOT

https://bitbucket/[user]/[project].git

https://bitbucket/[user]/[project]

http://bitbucket/[user]/[project].git

@Miuler I'm facing a very similar issue during the `maven prepare` when it is trying to push:

fatal: could not read Username for 'https://bitbucket.org': No such device or address


What do you mean by your response above? Are you saying that in the `pom.xml` we must not use https for the `scm` tag. Like this?

    <scm>    <connection>scm:git:http://bitbucket.org/[company]/[project].git</connection>        <developerConnection>scm:git:http://bitbucket.org/[company]/[project].git</developerConnection>
        <url>http://bitbucket.org/[company]/[project]</url>
        <tag>HEAD</tag>
    </scm>
 

I'm able to get this to work flawlessly with `https` from my local machine. But this seems to be not a well-documented process from bitbucket pipelines.

Could someone provide a sample bitbucket-pipelines.yml file? It seems you must provide a command that does not trigger an infinite loop:

git remote set-url origin ${BITBUCKET_GIT_HTTP_ORIGIN}
mvn -B -Dmaven.test.failure.ignores -f pom.xml release:clean release:prepare release:perform -DscmCommentPrefix="[skip ci]"


But what do before this? 

There are an amazing variety of answers out there for getting maven release to work, but none that seem to be complete and/or work.

This was the best example I could find:

It is is not complete either, but comes close to working.

Other issues to consider,

  • use SSH, not HTTPS
    • Do not reset the upstream repo for pushes like so many instructions suggest, as it is already done in the image and it sets up the proxy that is needed: 
      • git remote set-url origin ...
  • you will probably not want to do a manual release like in the example. Change both steps to automatic triggers.
    • If you do this, you must set the Prefix on the commit messages to be a token that BitBucket uses to prevent an infinite loop.
    • Also, if you require a commit message with a JIRA ticket number, you can use this same prefix to include a dummy value
  • Maven release:prepare not actually finishing all the steps it is supposed to do, but there is no error to make it obvious
  • You may want to rename the tag
  • Do not use git config --global when setting the 'user.email' and 'user.name', or you may end up with values that seem to be set by image automatically and thus prevent branch permissions from being able to be set effectively.
    • In raw commit: 
      From: bitbucket-pipelines <commits-noreply@bitbucket.org>

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket Pipelines

What We Learned When We Researched Open Source Vulnerabilities in 7 Popular Coding Languages

...hey are a part of us, shaping how we interact with the world around us. The same holds true for programming languages when we think about how different kinds of vulnerabilities raise their heads in t...

1,037 views 0 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you