I've recently started using Pipelines for my project and I solved most of my problems from testing to deployment with Rails.
When I used Pipelines for my feature and unit tests only I have handled everything in my default step because I wanted to know if my feature branches broke things. Since I want to use Pipelines as continuous deployment too I've found out that my default step is not invoked as soon as you specify something for a specific branch. The question is if there is a way to reuse code within the YAML file as my file has a lot of duplicated lines already. Or is there maybe a better way as what I do?
This is my current pipeline file, I have changed some values for privacy reasons.
image: ruby:2.5.0
pipelines:
default:
- step:
caches:
- bundler
script:
- curl -sL https://deb.nodesource.com/setup_8.x | bash -
- apt-get update && apt-get install -y nodejs apt-transport-https
- apt-get install -y build-essential libpq-dev cron vim imagemagick mysql-client
- export DATABASE_URL=mysql2://test_user:test_user_password@127.0.0.1/example_ci_test
- cp config/database.ci.yml config/database.yml && cp config/secrets.ci.yml config/secrets.yml
- bundle install --retry 5 --path vendor
- RAILS_ENV=test bundle exec rake db:drop db:create db:migrate
- bundle exec rspec --format documentation
services:
- redis
- mysql
master:
- step:
caches:
- bundler
script:
- curl -sL https://deb.nodesource.com/setup_8.x | bash -
- apt-get update && apt-get install -y nodejs apt-transport-https
- apt-get install -y build-essential libpq-dev cron vim imagemagick mysql-client
- export DATABASE_URL=mysql2://test_user:test_user_password@127.0.0.1/example_ci_test
- cp config/database.ci.yml config/database.yml && cp config/secrets.ci.yml config/secrets.yml
- bundle install --retry 5 --path vendor
- RAILS_ENV=test bundle exec rake db:drop db:create db:migrate
- bundle exec rspec --format documentation
services:
- redis
- mysql
- step:
caches:
- bundler
name: Deploy to integration
deployment: staging
script:
- curl -sL https://deb.nodesource.com/setup_8.x | bash -
- apt-get update && apt-get install -y nodejs apt-transport-https
- cp config/database.ci.yml config/database.yml && cp config/secrets.ci.yml config/secrets.yml
- gem install bundler
- RAILS_ENV=production bundle install --path vendor
- export DEPLOY_PATH=/home/x/integration.intern.x.com
- export SERVER_HOST=88.x.x.x
- export SERVER_PORT=22
- export SERVER_USER=x
- RAILS_ENV=production bundle exec rake docker:deploy
- step:
caches:
- bundler
name: Deploy to production
deployment: production
trigger: manual
script:
- curl -sL https://deb.nodesource.com/setup_8.x | bash -
- apt-get update && apt-get install -y nodejs apt-transport-https
- cp config/database.ci.yml config/database.yml && cp config/secrets.ci.yml config/secrets.yml
- gem install bundler
- RAILS_ENV=production bundle install --path vendor
- export DEPLOY_PATH=/home/x/intern.x.com
- export SERVER_HOST=88.x.x.x
- export SERVER_PORT=22
- export SERVER_USER=x
- RAILS_ENV=production bundle exec rake docker:deploy
definitions:
caches:
bundler: ./vendor
services:
redis:
image: redis
mysql:
image: mysql:5.7
environment:
MYSQL_DATABASE: example_ci_test
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
MYSQL_USER: test_user
MYSQL_PASSWORD: test_user_password
Thanks in advance!
@fuxx, you can use YAML anchors and references to reduce duplication in your pipelines yaml file, which are part of the YAML specification.
e.g Below I've step up 2 steps, with both steps re-using whats been defined in 'commonStep'.
commonStep: &commonStep
step:
script:
- echo "hello"
- echo "world"
pipelines:
default:
- <<: *commonStep
- <<: *commonStep
The first block of yaml steps up a step and assigns an anchor to it. We can then reference the anchor and inline the yaml associated with that anchor using '<<:'.
I just want to add that we have the following page as a reference on this topic:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It seems like if I use an anchor to create a Maven settings.xml file via a script in a step that it doesn't get found in the subsequent steps. Is this expected? Is there a workaround?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Maybe add some more keywords like "reusable steps" or "step as variables"
I was searching for this document for hours, but passed by YAML anchors many times
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.