1

Using a very simple Jenkinsfile such as:

echo "Current build number: ${manager.build.number}"
if (manager.setBuildNumber(1)) {
    echo "Build number is now: ${manager.build.number}"
    manager.createSummary("gear2.gif").appendText("<h2>Testing</h2>", false)
}

The output is:

[Pipeline] echo
Current build number: 3
[Pipeline] echo
Build number is now: 3
[Pipeline] End of Pipeline

I expect the second echo to be build number 1. This means the manager.createSummary() is getting applied to the current build number (3), not the intended one (1).

Any ideas? I've looked into the groovy-postbuild source code and it looks like it is actually getting the build from build.getParent().getBuildByNumber(buildNumber) as it's returning a not-null value, but perhaps the build it is returning is the current build regardless of what build number is provided?

FWIW, we are using the GitHub Organization and multi-branch plugins.

Gman
  • 63
  • 1
  • 8

1 Answers1

0

The build instance you get is the original build. Each time you call "manager", the plugin creates a new BadgeManager instance with the original build.

In order to perform your if block actions on the other build (1 in your case), you should use the same manager instance. for example:

echo "Current build number: ${manager.build.number}"
def mng = manager
if (mng.setBuildNumber(1)) {
    echo "Build number is now: ${mng.build.number}"
    mng.createSummary("gear2.gif").appendText("<h2>Testing</h2>", false)
}
Tidhar Klein Orbach
  • 2,896
  • 2
  • 30
  • 47
  • Thank you Tidhar. While this does work, none of the examples on the groovy-postbuild documentation (https://wiki.jenkins-ci.org/display/JENKINS/Groovy+Postbuild+Plugin) mention this so I'm a bit puzzled but glad it works :) – Gman Mar 27 '17 at 10:57