Passing Data From Groovy Post Build To Post Build Task Via Global Properties

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Passing Data From Groovy Post Build To Post Build Task Via Global Properties

santhosh soma
Hi All,

I have written groovy script to set the global environment variables as part of the post build groovy step. I could able to the set the properties but the properties are not refreshing by default while running next build.

Is there any way to refresh the global properties once we set through the groovy script.

import hudson.model.*
import hudson.slaves.EnvironmentVariablesNodeProperty
import jenkins.model.Jenkins

//Removing the environment variables if any before creating.
instance = Jenkins.getInstance()
globalNodeProperties = instance.getGlobalNodeProperties()
envVarsNodePropertyList = globalNodeProperties.getAll(EnvironmentVariablesNodeProperty.class)
newEnvVarsNodeProperty = null
envVars = null

if ( envVarsNodePropertyList == null || envVarsNodePropertyList.size() == 0 ) {
  newEnvVarsNodeProperty = new EnvironmentVariablesNodeProperty();
  envVars = newEnvVarsNodeProperty.getEnvVars()
} else {
  envVars = envVarsNodePropertyList.get(0).getEnvVars()


//Setting the environment variables again

def matcher = manager.getLogMatcher("(.*)Tests run: (.*), Failures: (.*), Errors:(.*), Skipped: (.*), Time elapsed:(.*)\$")
if (matcher?.matches()) {

def totalTests = as int;
def totalFailedTests = as int;
def totalErrorTests = as int;
def totalSkippedTests = as int;

def totalPassTests = totalTests - totalFailedTests - totalErrorTests -totalSkippedTests ;
def overallPassPercentage = (totalPassTests/totalTests) * 100 as int;

manager.listener.logger.println("totalTests count  "+totalTests)
manager.listener.logger.println("totalFailedTests count  "+totalFailedTests)
manager.listener.logger.println("totalErrorTests count  "+totalErrorTests)
manager.listener.logger.println("totalSkippedTests count  "+totalSkippedTests)
manager.listener.logger.println("totalPassTests count  "+totalPassTests)
manager.listener.logger.println("overallPassPercentage  "+overallPassPercentage)

envVars.put("totalTests", totalTests+"")
envVars.put("totalFailedTests", totalFailedTests+"")
envVars.put("totalErrorTests", totalErrorTests+"")
envVars.put("totalSkippedTests", totalSkippedTests+"")
envVars.put("totalPassTests", totalPassTests+"")
envVars.put("overallPassPercentage", overallPassPercentage+"")

I am getting the n-1 build values during N build execution in Post Build Task Step. Can someone help me on this.

Please let me know if we can achieve "Passing Data From Groovy Post Build To Post Build Task Via Global Properties" in any other way.


You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit
For more options, visit