Jenkins - Trigger parameterized build on other project
Add to A:
Post-build Actions → Trigger parameterized build on other projects:
- Projects to build:
B
- Trigger when build is: Complete (always trigger)
-
Add parameters → Predefined parameters:
A_HAS_BEEN_BUILT=YES
Add to B:
Meta Data → [✔] This build is parameterized → Add parameter → String parameter:
- Name:
A_HAS_BEEN_BUILT
- Default value:
NO
Post-build Actions → Trigger parameterized build on other projects:
- Projects to build:
C
- Trigger when build is: Stable [the default anyway]
-
Add parameters → Predefined parameters:
A_HAS_BEEN_BUILT=${A_HAS_BEEN_BUILT}
Add to C:
Meta Data → [✔] This build is parameterized_ → Add parameter → String parameter:
- Name:
A_HAS_BEEN_BUILT
- Default value:
NO
Build → Add Build step → Conditional step (single):
- Run?: Not
- !: Regular expression match
- Expression:
^YES$
- Label:
${ENV,var="A_HAS_BEEN_BUILT"}
- Expression:
- Builder: ... according to your needs ...
See Parameterized Build, Parameterized Trigger Plugin and Run Condition Plugin.
UPDATE 1
The settings given above induce the following:
- A builds → B builds → B is stable → C starts, but doesn't build
- B polls SCM → SCM changes → B builds → B is stable → C builds
According to the discussion the following is intended:
- A builds → B builds
- 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
Build → Add Build step → Conditional 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
- Projects to build:
- Build Triggers
kazerm
Updated on July 09, 2022Comments
-
kazerm almost 2 years
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