Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins - Trigger parameterized build on other project

How can I trigger a parameterized build only if the parent finished successfully AND it had changes (changes pushed to scm)?

Here is a scenario: I have 3 builds: A, B and C. B will built if it is called by A or it has changes. C should be built only if B finished successfully and if B was built because of scm changes and NOT because it was triggered by A

Thanks

like image 715
kazerm Avatar asked Jul 17 '15 21:07

kazerm


1 Answers

Add to A:

Post-build ActionsTrigger parameterized build on other projects:

  • Projects to build: B
  • Trigger when build is: Complete (always trigger)
  • Add parametersPredefined parameters: A_HAS_BEEN_BUILT=YES

Add to B:

Meta Data → [✔] This build is parameterized → Add parameterString parameter:

  • Name: A_HAS_BEEN_BUILT
  • Default value: NO

Post-build ActionsTrigger parameterized build on other projects:

  • Projects to build: C
  • Trigger when build is: Stable [the default anyway]
  • Add parametersPredefined parameters: A_HAS_BEEN_BUILT=${A_HAS_BEEN_BUILT}

Add to C:

Meta Data → [✔] This build is parameterized_ → Add parameterString parameter:

  • Name: A_HAS_BEEN_BUILT
  • Default value: NO

BuildAdd Build stepConditional step (single):

  • Run?: Not
  • !: Regular expression match
    • Expression: ^YES$
    • Label: ${ENV,var="A_HAS_BEEN_BUILT"}
  • Builder: ... according to your needs ...


See Parameterized Build, Parameterized Trigger Plugin and Run Condition Plugin.

UPDATE 1

The settings given above induce the following:

  1. A builds → B builds → B is stable → C starts, but doesn't build
  2. B polls SCM → SCM changes → B builds → B is stable → C builds

According to the discussion the following is intended:

  1. A builds → B builds
  2. B polls SCM → SCM changes → B builds → B is stable → C builds

UPDATE 2

To prevent C from being triggered at 1.:

  • Create an upstream project to B that polls the SCM and triggers B

  • Configure the following in B:

    Source Code Management → ◉ None

    Build Triggers

    • [   ] Poll SCM


    BuildAdd Build stepConditional step (single):

    • Run?: Execute shell / Execute Windows batch command
      • Command: ... SCM checkout commands; set exit status / ERRORLEVEL greater than 0 in case of no SCM changes ...
    • Builder: Trigger/call builds on other projects
      • Build Triggers
        • Projects to build: C
like image 197
Gerold Broser Avatar answered Oct 03 '22 23:10

Gerold Broser