How to use maven release plugin with bitbucket pipelines?

Zachary LaVallee May 13, 2019

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. 

 

2 answers

0 votes
Roney Stein September 2, 2021

To avoid the clone problem when running the relase:perform use the option localCheckout such as in the example using the command line:

 

mvn -B -s settings.xml -DlocalCheckout=true release:perform

 

To avoid the prepare commits from triggering other pipelines use the option scmCommentPrefix from the release plugin, with the "[skip ci]" content, in the command line or in the pom.xml configuration block like the example below:

 

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<tagNameFormat>version/@{project.version}</tagNameFormat>
<scmCommentPrefix>[skip ci] [maven]</scmCommentPrefix>
</configuration>
</plugin>

This way the two commits won't trigger the pipeline.

0 votes
Steven Vaccarella
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 23, 2019

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).

Zachary LaVallee June 13, 2019

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.

Miuler December 26, 2019

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
Kevin Coy February 15, 2020

@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? 

Kevin Coy February 18, 2020

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
AUG Leaders

Atlassian Community Events