Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can I configure my pipeline to control versioning?

Matt Black October 27, 2016

I'd like my Bitbucket Pipeline to control versioning of my Maven project.

Ideally, every time a change is made to the master branch, I want to create a new release and increment the version automatically.

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Thomas Turrell-Croft November 6, 2016

Hi

I have created a sample that shows how the Maven release plugin can be used in conjunction with Pipelines.

The Pipeline contains the following branches configuration:

master:
      - step:
          script:
            - git config --global user.email "$email"
            - git config --global user.name "$name"
            - mvn -batch-mode release:prepare -Dusername=$USERNAME -Dpassword=$PASSWORD -DscmCommentPrefix="[skip ci]" 
            - mvn release:perform -Dgoals=install
    develop:
      - step:
          script:
            - mvn clean install

The DscmCommentPrefix argument ensures that the release prepare goal does not trigger an additional Pipelines build. 

The release plugin require that the pom file contains the scm tag.

<scm>
    <url>https://example.com/pipelines-maven-sample</url>
    <connection>scm:git:https://example.com/pipelines-maven-sample.git</connection>
    <developerConnection>scm:git:https://example.com/pipelines-maven-sample.git</developerConnection>
  </scm>

You should use the maven release plugin version 2.5.3 or greater.

This sample assumes that all development is done in a development branch, when the development branch is considered stable it is merged to master.

Merging to master will run the maven release prepare and the release perform goals.

The release prepare goal will perform the following tasks:

  • Changes the version in the POM from n-SNAPSHOT to n
  • Commits the modified POMs
  • Tag the code with the version name
  • Changes the version in the POM to (n+1)-SNAPSHOT
  • Commits the modified POMs

Finally the release perform goal will:

  • Checkout the version tag
  • Run the install goal

The full sample can be seen at https://bitbucket.org/thomas_turrell/pipelines-maven-sample/overview

I hope that is useful for you.

Matt Black November 17, 2016

Thanks Thomas, that was very helpful.

Especially the tip about: -DscmCommentPrefix="[skip ci]" 

ushatil January 20, 2017

So, for $USERNAME, $PASSWORD, $name, and $email env vars, does that mean you created a BitBucket system user and injected all their creds as secure environment variables?

 

I would expect a better integration between Pipelines and BitBucket SCM, so I could just use settings and/or bitbucket-pipelines.yml to grant SCM Write access to a Pipelines executor without having to inject secure env vars.

Thomas Turrell-Croft June 25, 2017

Yes I inject the credentials.

I think you have three options for injecting the credentials:

  • Pass in your own username and password (probably quickest but least secure option)
  • Create a service account that has limited permissions (will require an additonal bitbucket user on your plan)
  • Use app passwords 

You could probably use SSH keys as well.

Whatever option you choose you will have to trust everyone that has write access to the Git repo.

If you wanted to avoid injecting credentials then you could create your own Docker image but you would have to store it in a private repro (which isn't currently supported by pipelines).

TAGS
AUG Leaders

Atlassian Community Events