Last active
April 26, 2018 14:57
-
-
Save martinda/ab13617fe7bcb663a7d40c4ea73de5bf to your computer and use it in GitHub Desktop.
Test jenkins-rest QueueItem parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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