semaphoreui / semaphore

Modern UI and powerful API for Ansible, Terraform, OpenTofu, PowerShell and other DevOps tools.
https://semaphoreui.com
MIT License
10.55k stars 1.06k forks source link

Allow to set custom playbook repository branch #501

Closed strangeman closed 3 years ago

strangeman commented 6 years ago

Currently, master is hardcoded (https://github.com/ansible-semaphore/semaphore/blob/develop/api/tasks/runner.go#L306).

This is not good, especially you have different branches for the different environments. I think we should add a new field "Branch" to "Repository" object.

twhiston commented 6 years ago

Currently I work around this with seperate repos in semaphore with the 'git@repo.com#branchname' naming scheme which deals with this pretty cleanly. If we added a way to select the branch I can see a few things we will need to care about....

If the repo has a single folder id 'repository_{id}' then between job runs its possible that the content of the repo will be changed as a new branch could be checked out. This checkout will have to force reset the repo files every time to ensure consistency. Thus locally altering the repo files to test changes will no longer be possible as we will have to force it to reset to a clean state every time.

We will need to be careful that jobs totally end before the next one begins so the repo is not changed under you while a task is being performed or you could end up with some pretty wild behaviour (related to #480)

We definitely need #495 unless we have a way to only select existing branches in the ui.

I think maybe this is too much work to target v2.5.0

strangeman commented 6 years ago

Good idea, 'git@repo.com#branchname' notation will help us achieve this feature without UI and DB scheme changes. Yeah, this is a big change. Perhaps, we should do it after https://github.com/ansible-semaphore/semaphore/issues/75 I think, we already did too much for 2.5.0. :) We fixed many old bugs and greatly improved CI/CD process.

twhiston commented 6 years ago

'git@repo.com#branchname' notation already works btw 😀

Agreed that we should do it after #75, i was actually thinking of moving that issue to 2.6.0 as we don't need it right now and it's another big change.

mmospanenko commented 2 years ago

any ideas how to use different branches per run? For example we have source code and playbooks in one repo, I want to run build or deploy particular version with identical config and sources (like BitBucket does - runs CI from commit). This is wrong way to hardcode/predefine pranch