4

Using a simple gitlab-ci I deploy my python script to digital ocean. The script part from the ci file looks like this:

/app/doctl apps create --spec my-app.yml

The Yaml file contains the information to create the app, and it has the branchname in it. I would like to be able to make that dynamic, as in, if I run the job on a certain branch, make that branch deploy. Currently it will always deploy main, as it is hardcoded in the config:

Relevant part of the config:

workers:
- environment_slug: python
  gitlab:
    branch: main
    repo: myname/appname
  name: app-name
  run_command: python runcommand.py

I'm not sure if it is possible to have the branch name as an environment variable or something? You can provide variables in the yaml itself for later use, but that's not for injecting the branch name as far as I know.

I hesitate to create a yaml 'template' and write something to parse the branch name in it with a script or something, that feels like a dirty solution?

Another 'solution' I thought up was to have the 'main' as the 'current release' branch, but to actually release from a different branch. A "deployed" branch. This would be equivalent to the main in most situations, but you could push some test-code to this branch. I'm not liking this much, as it is confusing what that branch contains, and it is more work then to just edit the file every time you want to push a different branch.

(The above yaml is a digital-ocean app spec, see: https://docs.digitalocean.com/products/app-platform/reference/app-spec/ )

Nanne
  • 64,065
  • 16
  • 119
  • 163

0 Answers0