Breadcrumbs

Configuring a Hotfix Trigger

This page provides some examples of how to configure the trigger conditions of build pipelines in various build systems.

GitHub Actions

on:
  push:
    branches:
    - master
    - 'releases/**'
  pull_request:
    branches:
    - master
    - 'releases/**'

See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#create

GitLab

To trigger a pipeline on the main branch of project-B when a tag is created in project-A, add the following job to project A’s .gitlab-ci.yml file:

trigger_pipeline:
  stage: deploy
  script:
    - 'curl --fail --request POST --form token=$MY_TRIGGER_TOKEN --form ref=main "https://gitlab.myorg.com/api/v4/projects/123456/trigger/pipeline"'
  rules:
    - if: $CI_COMMIT_TAG
  environment: production

In this example:

  • 123456 is the project ID for the project ID in which you want to trigger a pipeline (the Project ID is displayed at the top of every project’s landing page.)

  • The rules clause describes the conditions that cause the job to run - in this case every time a tag is added to the project.

  • MY_TRIGGER_TOKEN is a masked CI/CD variable that contains the trigger token.

See https://docs.gitlab.com/ee/ci/yaml/index.html and https://docs.gitlab.com/ee/ci/triggers/

Jenkins

If your Git platform isn’t configured to trigger a specific pipeline on branch creation you can use Jenkins to interrogate the commit trigger.

stage("Step 3: Production Deployment"){
    when {
        allOf {
            expression { env.BRANCH_NAME == "origin/master" }
            expression { params.merged == true }
            expression { params.current_status == "closed" }
        }
    }
    steps{
        echo 'Do some branch-specific stuff here!'
    } 
}

Bitbucket

pipelines:
  branches:          
    master:
    - step: *Build
    - step: 
        <<: *Deploy
        name: Deploy to Prod
        deployment: prod
        trigger: manual

  tags:
    '*.*.*': # Tagged Release Version - automatically build, ready for manual deployment to Prod
      - step: *Build
      - step: 
          <<: *Deploy
          name: Deploy to Prod
          deployment: prod
          trigger: manual

Azure DevOps

To trigger the pipeline when a new branch is created, you need to remove the path filter and only set branch filter.

trigger:
  branches:
    include:
    - main
    - releases/*
    - feature/*
    exclude:
    - releases/old*
    - feature/*-working

See https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=yaml&WT.mc_id=AZ-MVP-5003781#wildcards