hudson.slaves.NodePropertyDescriptor Java Examples
The following examples show how to use
hudson.slaves.NodePropertyDescriptor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RepairnatorPostBuild.java From repairnator with MIT License | 6 votes |
public void createGlobalEnvironmentVariables(String key, String value){ Jenkins instance = Jenkins.getInstance(); DescribableList<NodeProperty<?>, NodePropertyDescriptor> globalNodeProperties = instance.getGlobalNodeProperties(); List<EnvironmentVariablesNodeProperty> envVarsNodePropertyList = globalNodeProperties.getAll(EnvironmentVariablesNodeProperty.class); EnvironmentVariablesNodeProperty newEnvVarsNodeProperty = null; EnvVars envVars = null; if ( envVarsNodePropertyList == null || envVarsNodePropertyList.size() == 0 ) { newEnvVarsNodeProperty = new hudson.slaves.EnvironmentVariablesNodeProperty(); globalNodeProperties.add(newEnvVarsNodeProperty); envVars = newEnvVarsNodeProperty.getEnvVars(); } else { envVars = envVarsNodePropertyList.get(0).getEnvVars(); } envVars.put(key, value); try { instance.save(); } catch(Exception e) { System.out.println("Failed to create env variable"); } }
Example #2
Source File: AbstractKubernetesPipelineTest.java From kubernetes-plugin with Apache License 2.0 | 6 votes |
@Before public void configureCloud() throws Exception { cloud = setupCloud(this, name); createSecret(cloud.connect(), cloud.getNamespace()); cloud.getTemplates().clear(); cloud.addTemplate(buildBusyboxTemplate("busybox")); setupHost(); r.jenkins.clouds.add(cloud); DescribableList<NodeProperty<?>, NodePropertyDescriptor> list = r.jenkins.getGlobalNodeProperties(); EnvironmentVariablesNodeProperty newEnvVarsNodeProperty = new hudson.slaves.EnvironmentVariablesNodeProperty(); list.add(newEnvVarsNodeProperty); EnvVars envVars = newEnvVarsNodeProperty.getEnvVars(); envVars.put("GLOBAL", "GLOBAL"); envVars.put("JAVA_HOME_X", "java-home-x"); r.jenkins.save(); }
Example #3
Source File: DockerTemplate.java From docker-plugin with MIT License | 6 votes |
/** * Get a list of all {@link NodePropertyDescriptor}s we can use to define DockerSlave NodeProperties. */ @SuppressWarnings("cast") public List<NodePropertyDescriptor> getNodePropertiesDescriptors() { // Copy/paste hudson.model.Slave.SlaveDescriptor.nodePropertyDescriptors marked as @Restricted for reasons I don't get List<NodePropertyDescriptor> result = new ArrayList<>(); Collection<NodePropertyDescriptor> list = (Collection) Jenkins.getInstance().getDescriptorList(NodeProperty.class); for (NodePropertyDescriptor npd : DescriptorVisibilityFilter.applyType(DockerTransientNode.class, list)) { if (npd.isApplicable(DockerTransientNode.class)) { result.add(npd); } } final Iterator<NodePropertyDescriptor> iterator = result.iterator(); while (iterator.hasNext()) { final NodePropertyDescriptor de = iterator.next(); // see https://issues.jenkins-ci.org/browse/JENKINS-47697 if ("org.jenkinsci.plugins.matrixauth.AuthorizationMatrixNodeProperty".equals(de.getKlass().toJavaClass().getName())) { iterator.remove(); } } return result; }
Example #4
Source File: GlobalNodePropertiesTest.java From configuration-as-code-plugin with MIT License | 5 votes |
@Test public void configure() throws Exception { final Jenkins jenkins = Jenkins.get(); DescribableList<NodeProperty<?>, NodePropertyDescriptor> nodeProperties = jenkins.getGlobalNodeProperties(); Set<Map.Entry<String, String>> entries = ((EnvironmentVariablesNodeProperty) nodeProperties.get(0)).getEnvVars().entrySet(); assertEquals(1, entries.size()); Map.Entry<String, String> envVar = entries.iterator().next(); assertEquals("FOO", envVar.getKey()); assertEquals("BAR", envVar.getValue()); }
Example #5
Source File: JenkinsConfiguratorTest.java From configuration-as-code-plugin with MIT License | 5 votes |
@Test @Issue("Issue #173") @ConfiguredWithCode("SetEnvironmentVariable.yml") public void shouldSetEnvironmentVariable() throws Exception { final DescribableList<NodeProperty<?>, NodePropertyDescriptor> properties = Jenkins.get().getNodeProperties(); EnvVars env = new EnvVars(); for (NodeProperty<?> property : properties) { property.buildEnvVars(env, TaskListener.NULL); } assertEquals("BAR", env.get("FOO")); }
Example #6
Source File: KubernetesTest.java From kubernetes-plugin with Apache License 2.0 | 5 votes |
@Test @LocalData() public void upgradeFrom_0_10() throws Exception { List<PodTemplate> templates = cloud.getTemplates(); PodTemplate template = templates.get(0); DescribableList<NodeProperty<?>,NodePropertyDescriptor> nodeProperties = template.getNodeProperties(); assertEquals(1, nodeProperties.size()); ToolLocationNodeProperty property = (ToolLocationNodeProperty) nodeProperties.get(0); assertEquals(1, property.getLocations().size()); ToolLocation location = property.getLocations().get(0); assertEquals("Default", location.getName()); assertEquals("/custom/path", location.getHome()); assertEquals(GitTool.class, location.getType().clazz); assertEquals(cloud.DEFAULT_WAIT_FOR_POD_SEC, cloud.getWaitForPodSec()); }
Example #7
Source File: DockerFunctions.java From yet-another-docker-plugin with MIT License | 5 votes |
@SuppressWarnings("rawtypes") public static List<NodePropertyDescriptor> getNodePropertyDescriptors(Class<? extends Node> clazz) { List<NodePropertyDescriptor> result = new ArrayList<>(); Collection<NodePropertyDescriptor> list = (Collection) Jenkins.getInstance().getDescriptorList(NodeProperty.class); for (NodePropertyDescriptor npd : list) { if (npd.isApplicable(clazz)) { result.add(npd); } } return result; }
Example #8
Source File: ContainerStepExecution.java From kubernetes-plugin with Apache License 2.0 | 4 votes |
@Override public boolean start() throws Exception { LOGGER.log(Level.FINE, "Starting container step."); String containerName = step.getName(); String shell = step.getShell(); KubernetesNodeContext nodeContext = new KubernetesNodeContext(getContext()); EnvironmentExpander env = getContext().get(EnvironmentExpander.class); EnvVars globalVars = null; Jenkins instance = Jenkins.getInstance(); DescribableList<NodeProperty<?>, NodePropertyDescriptor> globalNodeProperties = instance.getGlobalNodeProperties(); List<EnvironmentVariablesNodeProperty> envVarsNodePropertyList = globalNodeProperties .getAll(EnvironmentVariablesNodeProperty.class); if (envVarsNodePropertyList != null && envVarsNodePropertyList.size() != 0) { globalVars = envVarsNodePropertyList.get(0).getEnvVars(); } EnvVars rcEnvVars = null; Run run = getContext().get(Run.class); TaskListener taskListener = getContext().get(TaskListener.class); if(run!=null && taskListener != null) { rcEnvVars = run.getEnvironment(taskListener); } decorator = new ContainerExecDecorator(); decorator.setNodeContext(nodeContext); decorator.setContainerName(containerName); decorator.setEnvironmentExpander(env); decorator.setWs(getContext().get(FilePath.class)); decorator.setGlobalVars(globalVars); decorator.setRunContextEnvVars(rcEnvVars); decorator.setShell(shell); getContext().newBodyInvoker() .withContext(BodyInvoker .mergeLauncherDecorators(getContext().get(LauncherDecorator.class), decorator)) .withCallback(new ContainerExecCallback(decorator)) .start(); return false; }