Branch conditions not behaving as expected

Hello there, I’ve been trying out drone deployments in our QA environment. However, I’ve been seeing some weird behavior related to the branch conditions.

Here’s an example of what I’m using.

- name: docker-qa
  image: plugins/docker
  settings:
    username:
      from_secret: DOCKER_ORG_LOGIN
    password:
      from_secret: DOCKER_ORG_PASSWORD
    repo: yourcompany/${DRONE_REPO_NAME}
    registry: yourcompany
    tags:
      - ${DRONE_COMMIT_BRANCH/release\//}
      - ${DRONE_COMMIT_BRANCH//\//-}-${DRONE_COMMIT_SHA:0:8}
    dockerfile: ./Dockerfile
  when:
    branch:
    - release/*
    event:
    - push

- name: deploy-kube-qa
  image: honestbee/drone-kubernetes
  settings:
    kubernetes_server: 
      from_secret: KUBERNETES_SERVER_QA
    kubernetes_cert: 
      from_secret: KUBERNETES_QA_CERT
    kubernetes_token: 
      from_secret: KUBERNETES_QA_TOKEN
    namespace: namespace
    deployment: deploy
    container: container
  repo: yourcompany/${DRONE_REPO_NAME}
  tags:
      - ${DRONE_COMMIT_BRANCH//\//-}-${DRONE_COMMIT_SHA:0:8}
  when:
    branch:
    - release/*
    event:
    - push

- name: deploy-kube-hotfix
  image: honestbee/drone-kubernetes
  settings:
    kubernetes_server: 
      from_secret: KUBERNETES_SERVER_QA
    kubernetes_cert: 
      from_secret: KUBERNETES_QA_CERT
    kubernetes_token: 
      from_secret: KUBERNETES_QA_TOKEN
    namespace: namespace
    deployment: deploy
    container: container
    repo: yourcompany/${DRONE_REPO_NAME}
    tags: 
      - ${DRONE_COMMIT_BRANCH//\//-}-${DRONE_COMMIT_SHA:0:8}
    when:
      branch:
      - hotfix/*
      event:
      - push

So, whenever I push a commit to a feature branch, both deploy steps are getting triggered.

Any help will be appreciated.

It looks like the indentation of the when clause is slightly off. It should work if you make the following adjustments:

  name: deploy-kube-hotfix
  image: honestbee/drone-kubernetes
  settings:
    kubernetes_server: 
      from_secret: KUBERNETES_SERVER_QA
    kubernetes_cert: 
      from_secret: KUBERNETES_QA_CERT
    kubernetes_token: 
      from_secret: KUBERNETES_QA_TOKEN
    namespace: namespace
    deployment: deploy
    container: container
    repo: yourcompany/${DRONE_REPO_NAME}
    tags: 
      - ${DRONE_COMMIT_BRANCH//\//-}-${DRONE_COMMIT_SHA:0:8}
-   when:
-     branch:
-     - hotfix/*
-     event:
-     - push
+ when:
+   branch:
+   - hotfix/*
+   event:
+   - push
1 Like