com.liferay.jenkins.results.parser.dependencies.invoke-jenkins-build.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.liferay.jenkins.results.parser
Show all versions of com.liferay.jenkins.results.parser
Liferay Jenkins Results Parser
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);