Search code examples
jenkinscicd

How does jenkins create multiple build triggers in a task, with different steps for each build trigger


I want multiple build triggers to be created in a task, and the steps for each build trigger to be different

in a task, I want to have three triggers, three different steps

1、Common build     setp 1 - setp3
2、Timing build      setp 4 - setp7
3、Specified rule construction   setp 8 - setp11

Solution

  • You could have a function that runs before the stages do which gets the reason for the build trigger. An example of this can be found in this answer. You could then have a set of env variables such as COMMON_BUILD = true/false, TIMING_BUILD = true/false depending on the result of the function.

    Before each stage you could then add a when condition (docs). So for example you could could put steps 1 - 3 in one stage and only run that stage when COMMON_BUILD == true:

    stage('1-3') {
      when {
        expression {
            return env.COMMON_BUILD
        }
      }
      steps {
        ...
      }
    }