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

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

Distribute build scripts across your project in Bitbucket Pipelines

Say you are maintaining a set of Atlassian Enterprise plugins in separate repositories on Bitbucket Cloud.

Say they share the same build commands in their `bitbucket-pipeline.yml` definition , for instance they all need to be able to release either a milestone or a final version

- parallel: 
- step:
name: Release Milestone
trigger: manual
caches:
- maven
script:
- git remote set-url origin ${BITBUCKET_GIT_SSH_ORIGIN}
- ./build/mvn-release.sh milestone
- step:
name: Release
trigger: manual
caches:
- maven
script:
- git remote set-url origin ${BITBUCKET_GIT_SSH_ORIGIN}
- ./build/mvn-release.sh final

In order to allow the maven release to go through and push git tags back to the repo, we will first need to generate an SSH Key from the repo and apply it on our account settings as per the documentation available here ... (this little detail is important to the next section)

Now the fun part is to figure out how to distribute those "build scripts" across multiple repositories 

maybe I can just consume it as a git submodule ?

The first idea that comes to mind would be to store those scripts into a separate repository and consume it as a git submodule 

cd my-plugin
git submodule add git@bitbucket.org:<workspace>/build-scripts.git

I can then update my pipeline definition as follow to first resolve the submodule 

script:
- git submodule update --init --recursive
- git remote set-url origin ${BITBUCKET_GIT_SSH_ORIGIN}
- ./build-scripts/mvn-release.sh milestone

 notice that `git submodule update --init --recursive` which is there to make sure build scripts are checked out, because they are not there by default on a simple clone

and when I want to update my repo to use a newer version of build-scripts I can use either of the following commands, and commit the changes back to my repo

  • git submodule update --recursive --remote

  • git pull --recurse-submodules 

curve ball

pipelines won't be able to resolve the submodule because it doesn't have access

Screen_Shot_2021-05-06_at_1_23_14_pm_png.png

one way to mitigate this problem is by generating an SSH Key from our repo, and apply it as access key to our new `build-scripts` repo 

however that will not work ... because remember, we have already assigned the key to our account so the maven release can go through succesfully

  Screen Shot 2021-05-06 at 5.24.35 pm.png

Morale , maybe don't use git submodules when dealing with build configurations

maybe use Bitbucket pipes ?

yes, this, do this !

It is a much better option documented here which basically allows you to pipe a Docker image into your pipeline and "execute" it prior to running the rest of your build steps.

So essentially you can write a pipe that copies over to your build context all the scripts you need.

Here is a summary of that documentation in images (the steps I followed)

  • define `pipe.yml`

build-scripts_–_pipe_yml_png.png

  • setup a `Dockerfile` to contain your entry point to be executed by Bitbucket Pipelines, plus the set of scripts you intend to distribute

build-scripts_–_Dockerfile.png

  • provide an entry point `activate.sh` that copies the scripts folder and makes it available to the build pipeline

build-scripts_–_activate_sh__1__png.png

  • now you can `docker build` and `docker push` your image, and update your readme, and also you must commit your changes with a git tag on them and push everything back to your new `build-scripts` repository.
  • and finally consume it as a pipe across all your repositories.
- parallel: 
- step:
name: Release Milestone
trigger: manual
caches:
- maven
script:
- pipe: <worskpace>/build-scripts:<git-tag>
- git remote set-url origin ${BITBUCKET_GIT_SSH_ORIGIN}
- ./atlas/mvn-release.sh milestone
- step:
name: Release
trigger: manual
caches:
- maven
script:
- pipe: <worskpace>/build-scripts:<git-tag>
- git remote set-url origin ${BITBUCKET_GIT_SSH_ORIGIN}
- ./atlas/mvn-release.sh final

 does it work ?

Hmm, yea

Screen_Shot_2021-05-09_at_7_06_08_pm_png.png

Screen_Shot_2021-05-09_at_7_07_38_pm__1__png.png

0 comments

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Confluence

🏑 Atlympic Event: Confluence

Hello Community!  Quick disclaimer: We are running a contest on Community (The Atlympics!) from July 23rd - August 8th of 2021. If you are interested in participating in this contest (prizes! ...

521 views 18 17
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