use of hudson.model.TextParameterDefinition in project jms-messaging-plugin by jenkinsci.
the class AmqMessagingPluginIntegrationTest method testSimpleCIEventWithMessagePropertiesAsVariable.
@Test
public void testSimpleCIEventWithMessagePropertiesAsVariable() throws Exception {
FreeStyleProject jobA = j.createFreeStyleProject();
jobA.getBuildersList().add(new Shell("echo CI_TYPE = $CI_TYPE"));
jobA.getBuildersList().add(new Shell("echo TEST_PROP1 = $TEST_PROP1"));
jobA.getBuildersList().add(new Shell("echo TEST_PROP2 = $TEST_PROP2"));
attachTrigger(new CIBuildTrigger(true, Collections.singletonList(getSubscriberProviderData("otopic", "CI_MESSAGE", "CI_TYPE = 'code-quality-checks-done' and CI_STATUS = 'failed'"))), jobA);
Thread.sleep(1000);
FreeStyleProject jobB = j.createFreeStyleProject();
jobB.addProperty(new ParametersDefinitionProperty(new TextParameterDefinition("MESSAGE_PROPERTIES", "CI_STATUS = failed\nTEST_PROP1 = GOT 1\nTEST_PROP2 = GOT 2", "")));
jobB.getBuildersList().add(new CIMessageBuilder(getPublisherProviderData("otopic", MessageUtils.MESSAGE_TYPE.CodeQualityChecksDone, "${MESSAGE_PROPERTIES}", "")));
j.buildAndAssertSuccess(jobB);
waitUntilScheduledBuildCompletes();
FreeStyleBuild lastBuild = jobA.getLastBuild();
j.assertBuildStatusSuccess(lastBuild);
j.assertLogContains("echo CI_TYPE = code-quality-checks-done", lastBuild);
j.assertLogContains("echo TEST_PROP1 = GOT 1", lastBuild);
j.assertLogContains("echo TEST_PROP2 = GOT 2", lastBuild);
}
use of hudson.model.TextParameterDefinition in project jms-messaging-plugin by jenkinsci.
the class CIBuildTrigger method getDefinedParameters.
private List<ParameterValue> getDefinedParameters(Job<?, ?> project) {
List<ParameterValue> parameters = new ArrayList<>();
ParametersDefinitionProperty properties = project.getProperty(ParametersDefinitionProperty.class);
if (properties != null && properties.getParameterDefinitions() != null) {
for (ParameterDefinition paramDef : properties.getParameterDefinitions()) {
ParameterValue param = null;
if (paramDef instanceof StringParameterDefinition) {
param = new StringParameterValue(paramDef.getName(), ((StringParameterDefinition) paramDef).getDefaultValue());
}
if (paramDef instanceof TextParameterDefinition) {
param = new TextParameterValue(paramDef.getName(), ((TextParameterDefinition) paramDef).getDefaultValue());
}
if (paramDef instanceof BooleanParameterDefinition) {
BooleanParameterValue defaultParameterValue = ((BooleanParameterDefinition) paramDef).getDefaultParameterValue();
param = new BooleanParameterValue(paramDef.getName(), Boolean.TRUE.equals(Objects.requireNonNull(defaultParameterValue).getValue()));
}
if (paramDef instanceof ChoiceParameterDefinition) {
param = ((ChoiceParameterDefinition) paramDef).getDefaultParameterValue();
}
if (param != null) {
parameters.add(param);
}
}
}
return parameters;
}
use of hudson.model.TextParameterDefinition in project jms-messaging-plugin by jenkinsci.
the class AmqMessagingPluginIntegrationTest method _testPipelineJobProperties.
public void _testPipelineJobProperties(boolean backwardCompatible) throws Exception {
List<Thread> leftoverFromPreviousRuns = getThreadsByName("ActiveMQ.*Task-.*");
leftoverFromPreviousRuns.addAll(getThreadsByName("CIBuildTrigger.*"));
for (Thread thread : leftoverFromPreviousRuns) {
thread.interrupt();
thread.stop();
}
WorkflowJob send = j.jenkins.createProject(WorkflowJob.class, "send");
send.setDefinition(new CpsFlowDefinition("node('master') {\n sendCIMessage" + " providerName: '" + DEFAULT_PROVIDER_NAME + "', " + " failOnError: true, " + " messageContent: '" + MESSAGE_CHECK_CONTENT + "', " + " messageProperties: 'CI_STATUS2 = ${CI_STATUS2}', " + " messageType: 'CodeQualityChecksDone'}", true));
// [expectedValue: number + '0.0234', field: 'CI_STATUS2']
String pd = "[$class: 'ActiveMQSubscriberProviderData', name: '" + DEFAULT_PROVIDER_NAME + "', selector: 'CI_NAME = \\'" + send.getName() + "\\'']";
if (backwardCompatible) {
pd = "providerData: " + pd;
} else {
pd = "providerList: [" + pd + "]";
}
WorkflowJob receive = j.jenkins.createProject(WorkflowJob.class, "receive");
receive.addProperty(new ParametersDefinitionProperty(new TextParameterDefinition("CI_MESSAGE", "", "")));
receive.setDefinition(new CpsFlowDefinition("def number = currentBuild.getNumber().toString()\n" + "properties(\n" + " [\n" + " pipelineTriggers(\n" + " [[$class: 'CIBuildTrigger', noSquash: false, " + pd + "]]\n" + " )\n" + " ]\n" + ")\nnode('master') {\n sleep 1\n}", true));
j.buildAndAssertSuccess(receive);
// Allow some time for trigger thread stop/start.
Thread.sleep(2000);
assertEquals("ActiveMQ.*Task- count", 1, getCurrentThreadCountForName("ActiveMQ.*Task-.*"));
assertEquals("CIBuildTrigger count", 1, getCurrentThreadCountForName("CIBuildTrigger.*"));
j.configRoundtrip(receive);
j.buildAndAssertSuccess(receive);
Thread.sleep(2000);
printThreadsWithName("ActiveMQ.*Task-.*");
printThreadsWithName("CIBuildTrigger.*");
assertEquals("ActiveMQ.*Task- count", 1, getCurrentThreadCountForName("ActiveMQ.*Task-.*"));
assertEquals("CIBuildTrigger count", 1, getCurrentThreadCountForName("CIBuildTrigger.*"));
// checks: [[expectedValue: '0.0234', field: 'CI_STATUS2']]
String randomNumber = "123456789";
for (int i = 0; i < 3; i++) {
QueueTaskFuture<WorkflowRun> build = send.scheduleBuild2(0, new ParametersAction(new TextParameterValue("CI_STATUS2", randomNumber, "")));
j.assertBuildStatusSuccess(build);
}
Thread.sleep(5000);
assertEquals("there are not 5 builds", 5, receive.getLastBuild().getNumber());
printThreadsWithName("ActiveMQ.*Task-.*");
printThreadsWithName("CIBuildTrigger.*");
assertEquals("ActiveMQ.*Task- count", 1, getCurrentThreadCountForName("ActiveMQ.*Task-.*"));
assertEquals("CIBuildTrigger count", 1, getCurrentThreadCountForName("CIBuildTrigger.*"));
pd = "[$class: 'ActiveMQSubscriberProviderData', checks: [[field: '" + MESSAGE_CHECK_FIELD + "', expectedValue: '" + MESSAGE_CHECK_VALUE + "']], name: 'test', selector: 'CI_NAME = \\'" + send.getName() + "\\'']";
if (backwardCompatible) {
pd = "providerData: " + pd;
} else {
pd = "providerList: [" + pd + "]";
}
receive.setDefinition(new CpsFlowDefinition("def number = currentBuild.getNumber().toString()\n" + "properties(\n" + " [\n" + " pipelineTriggers(\n" + " [[$class: 'CIBuildTrigger', noSquash: false, " + pd + "]]\n" + " )\n" + " ]\n" + ")\nnode('master') {\n sleep 1\n}", false));
scheduleAwaitStep(receive);
for (int i = 0; i < 3; i++) {
QueueTaskFuture<WorkflowRun> build = send.scheduleBuild2(0, new ParametersAction(new TextParameterValue("CI_STATUS2", randomNumber, "")));
j.assertBuildStatusSuccess(build);
Thread.sleep(1000);
}
Thread.sleep(2000);
assertEquals("there are not 9 builds", 9, receive.getLastBuild().getNumber());
for (int i = 1; i < 8; i++) {
j.assertBuildStatusSuccess(receive.getBuildByNumber(i));
}
printThreadsWithName("ActiveMQ.*Task-.*");
printThreadsWithName("CIBuildTrigger.*");
assertEquals("ActiveMQ.*Task- count", 1, getCurrentThreadCountForName("ActiveMQ.*Task-.*"));
assertEquals("CIBuildTrigger count", 1, getCurrentThreadCountForName("CIBuildTrigger.*"));
}
Aggregations