Skip to content

Commit de3451e

Browse files
committed
Merge branch 'dcoraboeuf-master'
see pull request #56. Displays the tree of upstream causes
2 parents b44aae1 + a73d517 commit de3451e

File tree

7 files changed

+103
-39
lines changed

7 files changed

+103
-39
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ For example:
6666
out.println params
6767
out.println 'Build Object Properties:'
6868
build.properties.each { out.println "$it.key -> $it.value" }
69-
70-
69+
70+
// output git commit info (git plugin)
71+
out.println build.environment.get('GIT_COMMIT')
72+
7173
// use it in the flow
7274
build("job1", parent_param1: params["param1"])
7375
build("job2", parent_workspace:build.workspace)

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<parent>
2828
<groupId>org.jenkins-ci.plugins</groupId>
2929
<artifactId>plugin</artifactId>
30-
<version>1.480</version>
30+
<version>1.509.1</version>
3131
</parent>
3232

3333
<groupId>com.cloudbees.plugins</groupId>

src/main/resources/com/cloudbees/plugins/flow/FlowCause/description.groovy

-35
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?jelly escape-by-default='true'?>
2+
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler">
3+
<j:set var="proj" value="${app.getItemByFullName(it.buildFlow)}"/>
4+
<j:choose>
5+
<j:when test="${proj != null}">
6+
<j:set var="build" value="${proj.getBuildByNumber(it.buildNumber)}"/>
7+
<j:choose>
8+
<j:when test="${build != null}">
9+
${%message(rootURL, proj.url, it.buildFlow, it.buildNumber)}
10+
</j:when>
11+
<j:otherwise>
12+
${%message_no_build(rootURL, proj.url, it.buildFlow, it.buildNumber)}
13+
</j:otherwise>
14+
</j:choose>
15+
</j:when>
16+
<j:otherwise>
17+
${%message_no_job(rootURL, null, it.buildFlow, it.buildNumber)}
18+
</j:otherwise>
19+
</j:choose>
20+
<j:if test="${!it.upstreamCauses.isEmpty()}">
21+
<br/>
22+
<j:out value="${%caused_by}"/>
23+
<ul>
24+
<j:forEach var="c" items="${it.upstreamCauses}">
25+
<li>
26+
<st:include page="description.jelly" it="${c}"/>
27+
</li>
28+
</j:forEach>
29+
</ul>
30+
</j:if>
31+
</j:jelly>

src/main/resources/com/cloudbees/plugins/flow/FlowCause/description.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@
2323
#
2424
message=Started by build flow <a href="{0}/{1}">{2}</a> build number <a href="{0}/{1}{3}">{3}</a>.
2525
message_no_build=Started by build flow <a href="{0}/{1}">{2}</a> build number {3}.
26-
message_no_job=Started by build flow "{2}" build number {3}.
26+
message_no_job=Started by build flow "{2}" build number {3}.
27+
caused_by=Originally caused by:

src/test/groovy/com/cloudbees/plugins/flow/ConcurrencyTest.groovy

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class ConcurrencyTest extends DSLTestCase {
5252
BuildFlow flow = new BuildFlow(Jenkins.instance, getName())
5353
flow.concurrentBuild = true;
5454
flow.dsl = """ build("concjob1", param1: build.number) """
55+
flow.onCreatedFromScratch()
5556

5657
def sfr1 = flow.scheduleBuild2(0)
5758
def fr1 = sfr1.waitForStart()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.cloudbees.plugins.flow
2+
3+
import com.gargoylesoftware.htmlunit.html.HtmlPage
4+
import hudson.model.Cause
5+
import hudson.model.CauseAction
6+
import org.junit.Rule
7+
import org.junit.Test
8+
import org.jvnet.hudson.test.JenkinsRule
9+
10+
import static org.junit.Assert.assertTrue
11+
12+
class FlowCauseTest {
13+
14+
@Rule
15+
public JenkinsRule j = new JenkinsRule()
16+
17+
protected BuildFlow createFlow(String name, String dsl) {
18+
def job = j.jenkins.createProject(BuildFlow, name)
19+
job.dsl = dsl
20+
job.save()
21+
return job
22+
}
23+
24+
/**
25+
* Given a pipeline A --> FLOW --> B, then the build for a B build must display Flow <-- A.
26+
*/
27+
@Test
28+
void 'Flow cause not blocking the upstream causes'() {
29+
// Jobs
30+
def a = createFlow('A', 'build("B")')
31+
def b = createFlow('B', 'build("C")')
32+
def c = createFlow('C', '')
33+
34+
// Triggers A
35+
j.assertBuildStatusSuccess(a.scheduleBuild2(0, new Cause.UserIdCause()))
36+
37+
// Checks the builds
38+
j.assertBuildStatusSuccess(b.builds.lastBuild)
39+
40+
// Last build in the sequence
41+
def build = c.builds.lastBuild
42+
j.assertBuildStatusSuccess(build)
43+
44+
// Checks the cause tree
45+
def causeAction = build.actions.find { it instanceof CauseAction } as CauseAction
46+
assert causeAction != null: "A cause action must be associated with the build"
47+
assert causeAction.causes.size() == 1
48+
def cause = causeAction.causes.first() as Cause.UpstreamCause
49+
assert cause.shortDescription == 'Started by build flow B#1'
50+
def upstreamCause = cause.upstreamCauses.first() as Cause.UpstreamCause
51+
assert upstreamCause.shortDescription == 'Started by upstream project "A" build number 1'
52+
53+
// Goes to the build status page of C
54+
HtmlPage page = j.createWebClient().goTo(c.builds.lastBuild.url)
55+
assert page.titleText == 'C #1 [Jenkins]'
56+
57+
// Just checking the different causes are in the page (a bit primitive)
58+
def bPosition = page.body.textContent.indexOf('Started by build flow B')
59+
assertTrue(bPosition > 0)
60+
assertTrue(page.body.textContent.indexOf('Started by upstream project A build number 1') > bPosition)
61+
62+
}
63+
64+
}

0 commit comments

Comments
 (0)