You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
I don't know if this is the right place for this, but I wanted to publish a solution I developed - mainly because it took me a little while to piece together, and I figure it may be useful to other people. I'm also keen to hear any feedback on the approach.
The problem
I have a Ruby Gem in a Bitbucket git repo, and I wanted to automate the process of testing and publishing new versions of the gem to RubyGems.org.
We've been having an awesome time rolling out Pipelines for all our Google App Engine hosted projects, but until now, our gem always had to be published manually. Could we put that into a CI/CD pipeline too?!
Configuring
bitbucket-pipelines.yml
image: ruby:2.6
pipelines:
pull-requests:
'**':
- step:
name: Run unit tests
caches:
- bundler
script:
- bundle install
- bundle audit check --update # <-- optional
- rake test
tags:
release-*:
- step:
name: Test and publish
caches:
- bundler
script:
- bundle install
- bundle audit check --update # <-- optional
- rake test
- mkdir -p /root/.gem
- touch /root/.gem/credentials
- chmod 0600 /root/.gem/credentials
- 'printf -- "---\n:rubygems_api_key: $GEM_HOST_API_KEY\n" > /root/.gem/credentials'
- rake build release:rubygem_push
definitions:
caches:
bundler: /usr/local/bundle
Explanation
This pipeline configuration defines two pipelines:
Key lines explained:
# Here we create the directory to store the RubyGem authentication file:
- mkdir -p /root/.gem
# We create the file and restrict access before we write sensitive data to it
- touch /root/.gem/credentials
# Also, if `credentials` is too open, RubyGems refuses to use it, much like ssh and ~/.ssh/id_rsa
- chmod 0600 /root/.gem/credentials
# Using echo is the obvious choice, but printf behaves more reliably across platforms
# The line has to be quoted and arguments must come after the --, otherwise Cthulhu is awakened
# This file should ultimately look identical to the one on your local machine.
- 'printf -- "---\n:rubygems_api_key: $GEM_HOST_API_KEY\n" > /root/.gem/credentials'
# `gem build && gem push XXX.gem` is the usual choice, but how do you know the filename to push?
# rake build && rake release:rubygem_push do the same thing, but take care of the changing filenames for you
- rake build release:rubygem_push
Notes
Umm, mostly because I don't know how!
When I created it, I think I only had 'Ask a question' and 'Start a discussion' as options.
Hi Aidan, thanks so much for sharing!
I'm compiling some examples for our documentation, and I think this might be a useful link to add to them. Would that be ok?
Yay!