Set build result with Groovy Postbuild Plugin using value of an environment variable

2,072 views
Skip to first unread message

Hans

unread,
Oct 28, 2011, 6:18:06 PM10/28/11
to Jenkins Users
Hello,

I am trying to figure out how I can use the value of an environment
variable to set the result of a build in Jenkins.

I have a Python script with does a few checks and sets an environment
variable in a file using the EnvInject Plugin.

I want to make a Groovy script that checks the results of this
variable. The file is formatted as "CMV_RESULT = FALSE/TRUE". I would
like to have some kind of Groovy script that does

if($CMV_RESULT = TRUE) {
buildSuccess()
} else {
buildFailure()
}

I have looked at the examples and the hudson.model.AbstractBuild
documentation but I cannot come up with a solution myself. I hope
somebody can help with this.

Kind regards,

Hans

Hans

unread,
Nov 4, 2011, 11:40:15 AM11/4/11
to Jenkins Users
Hello,

After some more searching I found another post somewhere with an
answer. Posting it here again for future reference. You can access an
environment variable in a Groovy post build script as follows:

manager.build.getEnvironment(manager.listener)['ENV_VAR']

Hopefully this will help somebody in the future.

Kind regards,

Hans

On Oct 28, 11:18 pm, Hans <h...@laissezfaire.nl> wrote:
> Hello,
>
> I am trying to figure out how I can use thevalueof anenvironmentvariabletosettheresultof abuildin Jenkins.
>
> I have a Python script with does a few checks and sets anenvironmentvariablein a fileusingthe EnvInjectPlugin.
>
> I want to make aGroovyscript that checks the results of thisvariable. The file is formatted as "CMV_RESULT = FALSE/TRUE". I would
> like to have some kind ofGroovyscript that does

w...@jfrogchina.com

unread,
Apr 10, 2017, 3:23:23 AM4/10/17
to Jenkins Users, ha...@laissezfaire.nl
def buildName = manager.envVars['JOB_NAME'];
def buildId = manager.envVars['BUILD_ID'];

manager.listener.logger.println(buildName);
Reply all
Reply to author
Forward
0 new messages