Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using "Drone Conditions" for running builds part of a repository

Tags:

drone.io

Our project is nested inside a mono-repository. Imagine this, we have a project in a "projects" folder. For example "projects/our-project". Well, we would like to be able to check our .drone.yml into just "our-project" but it appears Drone wants the configuration file at the root of the project, which is ok, we can work with that by changing the "commands" section of our builds. The trouble we are running into is that we only want to run the builds when something in "our-project" changes. I can't find a way to do that precisely with Drone so our next closest bet is conditions, I figure we can make namespace all branches for "our-project" like this "our-project/some-branch". Then we could set up a condition, to only run builds on "our-project/some-branch" and "master" this would limit the number of "fake builds" we are running from other projects branches:

build:
  when:
    branch:
      - master
      - our-project/*

The trouble is when we try to pull request from a "our-project/" branch to "master" the build won't run, I'm guessing because its being run on a merge commit which isn't in master or "our-project/"

My question is two fold: 1. What is the best way to leverage drone using the mono repository pattern (multiple projects, one repository) 2. If Drone doesn't have support for that pattern or isn't designed for it, what is the best work-around to limit "fake builds"

Note: We could at the beginning of our build check for changes in our sub-folder and return a green if there aren't any. I this a recommended approach?

like image 730
Merrick Christensen Avatar asked Feb 29 '16 17:02

Merrick Christensen


1 Answers

There's multiple solutions for this problem now.

As a start you can use exit (78) code which skips subsequent steps in pipeline but this workaround require you to define multiple pipelines that can be skipped.

Example:

- name: Check_src_for_changes
  image: alpine/git
  commands:
  - if (git diff --exit-code $DRONE_COMMIT_BEFORE $DRONE_COMMIT_AFTER -- src); then exit 78; fi

Also This is currently handled multiple extensions due to the new category of Drone plugin called a configuration plugin:

  • docs.drone.io/extensions/conversion
  • docs.drone.io/extensions/configuration

Anyone can create an extensions using drone starter projects

  • drone/boilr-convert
  • drone/boilr-config

Extensions can be used to override how Drone fetches a yaml allowing you to create or modify yaml files on the fly. There are multiple extensions that solve this problem today that you can use. Here are a few:

  • meltwater/drone-convert-pathschanged
  • bitsbeats/drone-tree-config
  • microadam/drone-config-changeset-conditional

For more about this issue please refer to issue#1021

like image 155
0xMH Avatar answered Sep 24 '22 21:09

0xMH