How can I pass a parameter in Jenkins from a build step to post-build step? I don't want to do it through a file, as it's just a simple string (version number) that I want to pass.

In post-build I use Groovy postbuild plugin to add this string to the summary of the build.


Update: I was in despair )) and decided to go via file route. Couldn't figure out how to get WORKSPACE env var in Groovy post-build step to get file from there.

Final update: So I ended up parsing build log, see my own answer below.

有帮助吗?

解决方案

I ended up printing information to the build log in the build step, and then parsing it in the post-build Groovy plugin.

A bit ugly workaround, I know, sometimes I miss TeamCity with it's simplicity...

Regex pattern below is obviously specific to my own build...

def matcher = manager.getLogMatcher("^Build Found:  [\\w\\s-]+_(\\d+\\.\\d+\\.\\d+)_\\d{8}(\\.\\d+)?\$")
if (matcher?.matches()) {
    def Version = matcher.group(1)
    manager.addShortText(Version, "grey", "white", "0px", "white")
    manager.createSummary("fingerprint.gif").appendText("Version: " + Version, false)
} else {
    manager.listener.logger.println("ERROR: Version number is not found in the build log")
    manager.buildFailure()
}

其他提示

Maybe using the envinject plugin ?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top