Skip to content

Instantly share code, notes, and snippets.

@martinda
Last active April 26, 2018 14:57
Show Gist options
  • Save martinda/ab13617fe7bcb663a7d40c4ea73de5bf to your computer and use it in GitHub Desktop.
Save martinda/ab13617fe7bcb663a7d40c4ea73de5bf to your computer and use it in GitHub Desktop.
Test jenkins-rest QueueItem parameters
Grab(group='com.cdancy', module='jenkins-rest', version='0.0.6')
import com.cdancy.jenkins.rest.JenkinsClient
import com.cdancy.jenkins.rest.domain.queue.QueueItem
import com.cdancy.jenkins.rest.features.JobsApi
import com.google.common.collect.Lists
JenkinsClient client = JenkinsClient.builder().build();
String jobXml = '''
<project>
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<hudson.model.StringParameterDefinition>
<name>a</name>
<description></description>
<defaultValue>1</defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>b</name>
<description></description>
<defaultValue>2</defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>c</name>
<description></description>
<defaultValue>3</defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
<scm class="hudson.scm.NullSCM"/>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders>
<hudson.tasks.Shell>
<command>#!/bin/bash
sleep 2</command>
</hudson.tasks.Shell>
</builders>
<publishers/>
<buildWrappers/>
</project>
'''
JobsApi jobsApi = client.api().jobsApi()
jobsApi.delete("test")
jobsApi.create("test",jobXml)
Map<String, List<String>> params = new HashMap<>();
params.put("a", Lists.newArrayList("1"));
int qId = jobsApi.buildWithParameters("test", params)
params.put("a", Lists.newArrayList("2"));
qId = jobsApi.buildWithParameters("test", params)
QueueItem queueItem = client.api().queueApi().queueItem(qId)
println(queueItem.params())
def expected = ["a":"1", "b":"2", "c":"3"]
assert(queueItem.params() == expected)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment