Byte Ebi's Logo

Byte Ebi 🍀

A Bit everyday A Byte every week

[CI/CD with Drone 101] 02 Setting Deployment Trigger Conditions (Pipeline)

Setting up deployment trigger conditions (pipeline) through Drone for automated deployment.

Ray

Utilizing Drone to establish a custom automated deployment service.
Drone is a CI/CD system tool developed in Golang.
In this article, we’ll configure multiple trigger conditions to initiate different deployment steps under various circumstances.

Multiple Trigger Conditions

In some projects, different events need to be performed on specific branches.
The following configuration can be referred to for such scenarios.

.drone.yml

---
################################################
#     dev: Update on every push to the branch     #
################################################
kind: pipeline
type: docker
name: backend_dev

steps:
  - name: submodules update
    image: alpine/git
    commands:
      - date
      - echo DRONE_REPO = ${DRONE_REPO}
      - echo DRONE_BRANCH = ${DRONE_BRANCH}
      - echo DRONE_COMMIT = ${DRONE_COMMIT}
      - echo DRONE_BUILD_NUMBER = ${DRONE_BUILD_NUMBER}
      - git submodule update --init --recursive

  - name: composer install
    image: composer:1.10.19
    commands:
      - composer install --ignore-platform-reqs

trigger:
  branch:
    - dev
  event:
    - push

---
################################################
#    stage: Execution based on schedule set     #
################################################
kind: pipeline
type: docker
name: backend_stage

steps:
  - name: submodules update
    image: alpine/git
    commands:
      - date
      - echo DRONE_REPO = ${DRONE_REPO}
      - echo DRONE_BRANCH = ${DRONE_BRANCH}
      - echo DRONE_COMMIT = ${DRONE_COMMIT}
      - echo DRONE_BUILD_NUMBER = ${DRONE_BUILD_NUMBER}
      - git submodule update --init --recursive

  - name: composer install
    image: composer:1.10.19
    commands:
      - composer install --ignore-platform-reqs

trigger:
  event:
    - cron
  cron:
    - every2hour

---
################################################
# production: Deploy using git tag triggering  #
################################################
kind: pipeline
type: docker
name: backend_production

steps:
  - name: submodules update
    image: alpine/git
    commands:
      - date
      - echo DRONE_REPO = ${DRONE_REPO}
      - echo DRONE_TAG = ${DRONE_TAG}
      - echo DRONE_COMMIT = ${DRONE_COMMIT}
      - echo DRONE_BUILD_NUMBER = ${DRONE_BUILD_NUMBER}
      - git submodule update --init --recursive

  - name: composer install
    image: composer:1.10.19
    commands:
      - composer install --no-dev --ignore-platform-reqs

trigger:
  event:
    - tag

If the dev branch is pushed, only the dev_check_info and dev_run_update actions will be executed.
Conversely, actions for pushing to the testing branch will wait until the specified schedule every2hour is triggered before execution.

This setup allows for different operations based on different branches, which is useful when, for example, deciding whether to include debugging mode in the startup commands.
If different environments are deployed on different servers or have different deployment processes, this configuration proves to be convenient.

Each pipeline operates independently, executing different steps based on the trigger settings.
Pushing code to the dev branch will only trigger the backend_dev pipeline and its internal steps.
Alternatively, tagging in version control, when a new tag is pushed and detected by the webhook, triggers the backend_production.
Cron Jobs can also be established for scheduled executions, as demonstrated by the backend_stage setting, which listens for the every2hour schedule.

For more condition settings, refer to the official documentation: Pipelines Conditions
Learn more about Pipelines: Pipelines Overview

Recent Posts

Categories

Tags