In my current project, I start testing a task by deploying the related branch to the staging environment after its code review phase is done. Deploying the branch takes almost an hour because of the complexity of our application. We did not want to trigger the deployment for each commit since it is a costly process. So we put a block step for the deployment part in the pull request pipeline. However, developers sometimes forgot to unblock this step when the task was ready for testing. It means I will have to wait for an hour to start testing when a branch is not deployed but ready for testing. I know it is not the best solution and it does not solve all the problems completely but I came up with a quick improvement:

We use the id of the related Jira task while naming a branch. I wrote a small script to send an API request to Jira with the branch name and checked the status of the task. If the task is not in the "Ready for QA" or "In QA" sections, then I added the block step. As a result, when the task is in the testing phase, the deployment to the test environments initiates automatically.

 - label: "Deploy to staging if the task is in the testing phase"
    key: "auto-deploy"
    command: python check_jira_status.py
    soft_fail: true

  - wait: ~

  - command : |
      if [ $$(buildkite-agent step get "outcome" --step "auto-deploy") == "soft_failed" ]; then
        cat <<- YAML | buildkite-agent pipeline upload
        steps:
          - block: ":rocket: Deploy it!"
      YAML
      fi
  
  - wait: ~

Thus, I was able to add a conditional block step and save the time we lost when we forgot to unblock the deployment step. This was especially great for the commits made during the testing phase. As I said before, it does not solve all the problems; if the task is moved to the testing phase after a commit, I still need to unblock the step manually. I am also planning to trigger the deployment when the task status is changed by using Jira webhooks. However, I didn't have time to do that, so I applied the quickest solution for now. I also wanted to share this with you because the conditional blocking step is not clearly explained in the Buildkite documentation. I hope it helps for you too.

Buildkite: Conditional Block Step