Any way to specify branch as command line deploy argument, to override default branch setting in wordpress_sites.yml?

I use GitFlow workflow, and will often want to deploy a feature branch to a remote stage server, and not the default branch that is in my environment’s wordpress_sites.yml.

My way of doing this has been to modify the environment’s wordpress_sites.yml before running the deploy playbook, to set the branch value each time, and then running

ansible-playbook deploy.yml -e " env=staging"

Is there a way to specify the branch to deploy from the command line as an argument, without changing the file each time? Is some argument like -e " env=staging branch=feature/myfeature" possible?

I looked but couldn’t find anything. My method is working, but not ideal.

How about putting a variable in branch?

# group_vars/staging/wordpress_sites.yml
- branch: master
+ branch: "{{ branch | default('master') }}"

Then deploy with -e branch=feature/myfeature


Perfect, that’s exactly what I was looking for. Thank you.

1 Like

@fullyint is this still a valid option to deal with the deploy of different branches?
i saw that it is an old post (2018), so I am wondering if it is still the best solution or there is a better way these days with the latest version of trellis.

as @mmccaff , I would like to deploy a branch with a new feature on the staging and then if all ok also on the production, so I am looking for a good way to deal with this.

This seems a pretty neat solution - what do you think could be better?

Also, I’m still learning managing a repo and git, but why would you deploy a branch to Production? Wouldn’t you test your branch on staging and the merge it into master and deploy that? I’m curious about your use case…

it is ok to me, I was just wondering if there is some trellis’s new feature for this, because this post is 2 years old, and I know that trellis is always on the move :slight_smile:

I am doing a sort of A/B testing, the client wants to see how the page performs with a different layout, so I thought that creating a branch would be a good option for this scope. (not sure if there is a better approach for this).

happy to hear a different approach.

Nothing has changed. That’s still the best/only option :slight_smile:

ok thanks :slight_smile: :+1:

hey @swalkinshaw, is there a way to pass the branch arg through the trellis-cli?

Something like $ trellis deploy staging feature/branch-name ?

No, sorry. That command just mirrors the functionality of the existing deploy script. I think it would be a good addition though.

1 Like

cool no worries :+1: I’ll pop over a feature request or PR if I can figure it out!