Different build command per branch

android

#1

Is there a way to specify different build commands based on the the branch the build was triggered from?

For android specifically I’d like to be able to build 1 flavor+buildType per branch.
ex:
for branch/master: gradlew assembleMasterDebug
for branch/full: gradlew assembleFullRelease

This differentiation is currently available for the deployment step, but not the test step where the build happens.


#2

The circle.yml file is per branch, so each branch can have a different one. Will that meet your needs?


#3

Could you explain what you mean by each branch can have a different circle.yml? Maybe I’m missing something.

As best as I can tell from https://circleci.com/docs/1.0/configuration/ the only place you can do per-branch config is in the deployment phase. I need per-branch config in the test phase where the apk is built.


#4

What he means is that when you push your branch to Github, and then CI pulls it and starts doing stuff. Well you pushed code that is specific to your branch. Your circle.yml is part of that branches code.
All you need to do is make your circle.yml files specific to their branch.

So in your master branch, your circle.yml calls gradlew assembleMasterDebug
In you full branch, your circle.yml calls gradlew assembleFullRelease instead.

As long as you keep the circle.yml files separate, it will work.


#5

And then as soon as I merge master into full the circle.yml on full will have both gradlew assembleMasterDebug and gradlew assembleFullRelease.

Unless theres some way to keep circleci.yml from being merged that isn’t manual?


#6

Ah, I misunderstood and thought the two branches were not going to be merged. In that case you are looking for something like this.


#7

You have access to https://circleci.com/docs/1.0/environment-variables/

One of them being $CIRCLE_BRANCH which is the name of the branch. You can check that and do different things in your code/commands.


#8

Note when using the suggested method by @oppianmatt, the following does not work (using dependencies section as example)

dependencies:
  override:
    - [ $CIRCLE_BRANCH = 'master' ] && run_something

But the following does work

dependencies:
  override:
    - if [ $CIRCLE_BRANCH = 'master' ]; then run_something; fi

Unfortunately these steps will still pollute the build output, but at least you can control the execution of commands for a specific branch.

I would like to see CircleCI support the following

dependencies:
  branch: master
    override:
      - run_something

#9

Is this going to happen someday? The deployment section already supports the branch filter - would be nice to have it in test or dependencies too!


#10

Still no resolution for this after almost a year?


#11

I used the code in yml which is based on branch

machine:
services:
- docker

general:
branches:
only:
- develop
- release

dependencies:
override:
- |
if [ $CIRCLE_BRANCH = ‘develop’ ]; then
docker build --build-arg branch=$CIRCLE_BRANCH --no-cache=true -t latest .
docker push latest
fi
if [ $CIRCLE_BRANCH = ‘release’ ]; then
docker build --build-arg branch=$CIRCLE_BRANCH --no-cache=true -t release .
docker push release
fi


#13