All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liferay.jenkins.results.parser.dependencies.invoke-jenkins-build.groovy Maven / Gradle / Ivy

The newest version!
import org.jvnet.jenkins.plugins.nodelabelparameter.LabelParameterDefinition;
import org.jvnet.jenkins.plugins.nodelabelparameter.LabelParameterValue;

Map parameters = new HashMap<>();

${parameters}

Map topLevelItems = Jenkins.instance.getItemMap();

TopLevelItem topLevelItem = topLevelItems.get("${jenkinsJobName}");

List parameterValues = new ArrayList<>();

JobProperty jobProperty = topLevelItem.getProperty("hudson.model.ParametersDefinitionProperty");

for (ParameterDefinition parameterDefinition : jobProperty.getParameterDefinitions()) {
	String parameterName = parameterDefinition.getName();

	String parameterValue = parameters.get(parameterName);

	if ((parameterValue == null) || parameterValue.isEmpty()) {
		parameterValue = parameterDefinition.defaultValue;
	}

	if (parameterDefinition instanceof StringParameterDefinition) {
		parameterValues.add(new StringParameterValue(parameterName, parameterValue));
	}
	else if (parameterDefinition instanceof LabelParameterDefinition) {
		parameterValues.add(new LabelParameterValue(parameterName, parameterValue));
	}
}

def waitingItem = Jenkins.instance.queue.schedule(topLevelItem, 0, new ParametersAction(parameterValues));

if (waitingItem == null) {
	for (Queue.Item item : Jenkins.instance.queue.getItems()) {
		if (waitingItem != null) {
			break;
		}

		for (Action action : item.getActions()) {
			if (!(action instanceof ParametersAction)) {
				continue;
			}

			if (!parameterValues.equals(action.getAllParameters())) {
				continue;
			}

			waitingItem = item;

			break;
		}
	}
}

def jsonBuilder = new groovy.json.JsonBuilder()

jsonBuilder queueId: waitingItem.getId()

println(jsonBuilder);




© 2015 - 2024 Weber Informatics LLC | Privacy Policy