hudson.slaves.EnvironmentVariablesNodeProperty Java Examples
The following examples show how to use
hudson.slaves.EnvironmentVariablesNodeProperty.
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: IntegrationTest.java From warnings-ng-plugin with MIT License | 6 votes |
@SuppressWarnings({"PMD.AvoidCatchingThrowable", "IllegalCatch"}) protected DumbSlave createDockerContainerAgent(final DockerContainer dockerContainer) { try { SystemCredentialsProvider.getInstance().getDomainCredentialsMap().put(Domain.global(), Collections.singletonList( new UsernamePasswordCredentialsImpl(CredentialsScope.SYSTEM, "dummyCredentialId", null, "test", "test") ) ); DumbSlave agent = new DumbSlave("docker", "/home/test", new SSHLauncher(dockerContainer.ipBound(22), dockerContainer.port(22), "dummyCredentialId")); agent.setNodeProperties(Collections.singletonList(new EnvironmentVariablesNodeProperty( new Entry("JAVA_HOME", "/usr/lib/jvm/java-8-openjdk-amd64/jre")))); getJenkins().jenkins.addNode(agent); getJenkins().waitOnline(agent); return agent; } catch (Throwable e) { throw new AssumptionViolatedException("Failed to create docker container", e); } }
Example #2
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 #3
Source File: DockerAgentTest.java From docker-workflow-plugin with MIT License | 6 votes |
@BeforeClass public static void setUpAgent() throws Exception { s = j.createOnlineSlave(); s.setLabelString("some-label docker"); s.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("ONAGENT", "true"), new EnvironmentVariablesNodeProperty.Entry("WHICH_AGENT", "first"))); s.setNumExecutors(2); s2 = j.createOnlineSlave(); s2.setLabelString("other-docker"); s2.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("ONAGENT", "true"), new EnvironmentVariablesNodeProperty.Entry("WHICH_AGENT", "second"))); //setup credentials for docker registry CredentialsStore store = CredentialsProvider.lookupStores(j.jenkins).iterator().next(); password = System.getProperty("docker.password"); if(password != null) { UsernamePasswordCredentialsImpl globalCred = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "dockerhub", "real", "jtaboada", password); store.addCredentials(Domain.global(), globalCred); } }
Example #4
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 #5
Source File: EnvInterpolationTest.java From appcenter-plugin with MIT License | 5 votes |
@Before public void setUp() throws IOException { freeStyleProject = jenkinsRule.createFreeStyleProject(); freeStyleProject.getBuildersList().add(TestUtil.createFile("three/days/xiola.ipa")); freeStyleProject.getBuildersList().add(TestUtil.createFile("three/days/blue.zip")); freeStyleProject.getBuildersList().add(TestUtil.createFile("three/days/linear-notes.md", "I prepared the room tonight with Christmas lights.")); final EnvironmentVariablesNodeProperty prop = new EnvironmentVariablesNodeProperty(); final EnvVars envVars = prop.getEnvVars(); envVars.put("OWNER_NAME", "janes-addiction"); envVars.put("APP_NAME", "ritual-de-lo-habitual"); envVars.put("PATH_TO_APP", "three/days/xiola.ipa"); envVars.put("BUILD_VERSION", "1.2.3"); envVars.put("PATH_TO_DEBUG_SYMBOLS", "three/days/blue.zip"); envVars.put("DISTRIBUTION_GROUPS", "casey, niccoli"); envVars.put("RELEASE_NOTES", "I miss you my dear Xiola"); envVars.put("PATH_TO_RELEASE_NOTES", "three/days/linear-notes.md"); jenkinsRule.jenkins.getGlobalNodeProperties().add(prop); final AppCenterRecorder appCenterRecorder = new AppCenterRecorder( "at-this-moment-you-should-be-with-us", "${OWNER_NAME}", "${APP_NAME}", "${PATH_TO_APP}", "${DISTRIBUTION_GROUPS}" ); appCenterRecorder.setBuildVersion("${BUILD_VERSION}"); appCenterRecorder.setPathToDebugSymbols("${PATH_TO_DEBUG_SYMBOLS}"); appCenterRecorder.setReleaseNotes("${RELEASE_NOTES}"); appCenterRecorder.setPathToReleaseNotes("${PATH_TO_RELEASE_NOTES}"); appCenterRecorder.setBaseUrl(mockWebServer.url("/").toString()); freeStyleProject.getPublishersList().add(appCenterRecorder); }
Example #6
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 #7
Source File: TestUtils.java From phabricator-jenkins-plugin with MIT License | 4 votes |
public static void setEnvironmentVariables(JenkinsRule j, Map<String, String> params) throws IOException { EnvironmentVariablesNodeProperty prop = new EnvironmentVariablesNodeProperty(); EnvVars envVars = prop.getEnvVars(); envVars.putAll(params); j.jenkins.getGlobalNodeProperties().add(prop); }
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; }
Example #9
Source File: FreestyleTest.java From yet-another-docker-plugin with MIT License | 4 votes |
@Override public Boolean call() throws Throwable { final Jenkins jenkins = Jenkins.getInstance(); String logName = "com.github.kostyasha.yad"; final LogRecorder logRecorder = new LogRecorder(logName); logRecorder.targets.add(new LogRecorder.Target("com.github.kostyasha.yad", Level.ALL)); jenkins.getLog().logRecorders.put("logName", logRecorder); logRecorder.save(); // prepare jenkins global (url, cred) JenkinsLocationConfiguration.get().setUrl(String.format("http://%s:%d", dockerUri.getHost(), jenkinsPort)); SystemCredentialsProvider.getInstance().getCredentials().add(dockerServerCredentials); //verify doTestConnection final DescriptorImpl descriptor = (DescriptorImpl) jenkins.getDescriptor(DockerConnector.class); checkFormValidation(descriptor.doTestConnection(dockerUri.toString(), "", dockerServerCredentials.getId(), connectorType, 10 * 1000, 11 * 1000)); // checkFormValidation(descriptor.doTestConnection(dockerUri.toString(), "", // dockerServerCredentials.getId(), JERSEY, 10 * 1000, 11 * 1000)); // checkFormValidation(descriptor.doTestConnection(dockerUri.toString(), "", // dockerServerCredentials.getId(), OKHTTP, 10 * 1000, 11 * 1000)); // prepare Docker Cloud final DockerConnector dockerConnector = new DockerConnector(dockerUri.toString()); dockerConnector.setCredentialsId(dockerServerCredentials.getId()); dockerConnector.setConnectTimeout(10 * 1000); dockerConnector.setReadTimeout(0); dockerConnector.setConnectorType(connectorType); dockerConnector.testConnection(); //launcher final DockerComputerJNLPLauncher launcher = new DockerComputerJNLPLauncher(); launcher.setNoCertificateCheck(true); launcher.setJvmOpts("-XX:-PrintClassHistogram"); final DockerPullImage pullImage = new DockerPullImage(); pullImage.setPullStrategy(PULL_LATEST); //remove final DockerRemoveContainer removeContainer = new DockerRemoveContainer(); removeContainer.setRemoveVolumes(true); removeContainer.setForce(true); //lifecycle final DockerContainerLifecycle containerLifecycle = new DockerContainerLifecycle(); containerLifecycle.setImage(slaveImage); containerLifecycle.setPullImage(pullImage); containerLifecycle.setRemoveContainer(removeContainer); //template final Entry entry = new Entry("super-key", TEST_VALUE); final EnvironmentVariablesNodeProperty nodeProperty = new EnvironmentVariablesNodeProperty(entry); final ArrayList<NodeProperty<?>> nodeProperties = new ArrayList<>(); nodeProperties.add(nodeProperty); nodeProperties.add(new DockerNodeProperty(CONTAINER_ID, CLOUD_ID, DOCKER_HOST)); final DockerSlaveTemplate slaveTemplate = new DockerSlaveTemplate(); slaveTemplate.setMaxCapacity(4); slaveTemplate.setLabelString(DOCKER_CLOUD_LABEL); slaveTemplate.setLauncher(launcher); slaveTemplate.setMode(Node.Mode.EXCLUSIVE); slaveTemplate.setRetentionStrategy(new DockerOnceRetentionStrategy(10)); slaveTemplate.setDockerContainerLifecycle(containerLifecycle); slaveTemplate.setNodeProperties(nodeProperties); final List<DockerSlaveTemplate> templates = new ArrayList<>(); templates.add(slaveTemplate); final DockerCloud dockerCloud = new DockerCloud( DOCKER_CLOUD_NAME, templates, 3, dockerConnector ); jenkins.clouds.add(dockerCloud); jenkins.save(); // either xmls a half broken return true; }
Example #10
Source File: DockerCloudTest.java From yet-another-docker-plugin with MIT License | 4 votes |
@Override public void before() throws Exception { final DockerServerCredentials dockerServerCredentials = new DockerServerCredentials( CredentialsScope.GLOBAL, // scope null, // id "description", //desc "keypem", "certpem", "capem" ); SystemCredentialsProvider.getInstance().getCredentials().add(dockerServerCredentials); final EnvironmentVariablesNodeProperty.Entry entry = new EnvironmentVariablesNodeProperty.Entry("kee", "vasdfs"); final EnvironmentVariablesNodeProperty variablesNodeProperty = new EnvironmentVariablesNodeProperty(singletonList(entry)); final DockerConnector connector = new DockerConnector("http://sdfs.com:234"); connector.setCredentialsId(dockerServerCredentials.getId()); connector.setConnectTimeout(1001); connector.setReadTimeout(1002); final DockerPullImage pullImage = new DockerPullImage(); pullImage.setCredentialsId(""); pullImage.setPullStrategy(DockerImagePullStrategy.PULL_ALWAYS); final DockerComputerJNLPLauncher launcher = new DockerComputerJNLPLauncher(); launcher.setLaunchTimeout(100); launcher.setUser("jenkins"); launcher.setJenkinsUrl("http://jenkins"); launcher.setJvmOpts("-blah"); launcher.setSlaveOpts("-more"); launcher.setNoCertificateCheck(true); launcher.setNoReconnect(false); final DockerCreateContainer createContainer = new DockerCreateContainer(); createContainer.setBindAllPorts(true); createContainer.setBindPorts("234"); createContainer.setCommand("sdfff"); createContainer.setCpuShares(3); createContainer.setDnsHosts(singletonList("dsf")); createContainer.setEnvironment(singletonList("sdf")); createContainer.setExtraHosts(singletonList("hoststs")); createContainer.setHostname("hostname.local"); createContainer.setMacAddress("33:44:33:66:66:33"); createContainer.setMemoryLimit(33333333L); createContainer.setPrivileged(false); createContainer.setTty(false); createContainer.setVolumes(singletonList("ssdf:/sdfsdf/sdf")); createContainer.setVolumesFrom(singletonList("sdfsd:/sdfsdf")); createContainer.setDevices(singletonList("/dev/sdc:/dev/sdc:rw")); createContainer.setCpusetCpus("1"); createContainer.setCpusetMems("2"); createContainer.setLinksString("some"); createContainer.setShmSize(102L); createContainer.setRestartPolicy(new DockerContainerRestartPolicy(NO, 0)); createContainer.setWorkdir("workdir"); createContainer.setUser("user"); createContainer.setDockerLabels(singletonList("testlabel=testvalue")); final DockerStopContainer stopContainer = new DockerStopContainer(); stopContainer.setTimeout(100); final DockerRemoveContainer removeContainer = new DockerRemoveContainer(); removeContainer.setForce(true); removeContainer.setRemoveVolumes(true); final DockerContainerLifecycle containerLifecycle = new DockerContainerLifecycle(); containerLifecycle.setImage("sdf/sdf:df"); containerLifecycle.setPullImage(pullImage); containerLifecycle.setCreateContainer(createContainer); containerLifecycle.setStopContainer(stopContainer); containerLifecycle.setRemoveContainer(removeContainer); final DockerSlaveTemplate dockerSlaveTemplate = new DockerSlaveTemplate(); dockerSlaveTemplate.setDockerContainerLifecycle(containerLifecycle); dockerSlaveTemplate.setLabelString("some-label"); dockerSlaveTemplate.setLauncher(launcher); dockerSlaveTemplate.setMaxCapacity(233); dockerSlaveTemplate.setMode(Node.Mode.EXCLUSIVE); dockerSlaveTemplate.setNodeProperties(singletonList(variablesNodeProperty)); dockerSlaveTemplate.setRemoteFs("/remotefs"); dockerSlaveTemplate.setNumExecutors(1); // need to be verified with other retention strategy dockerSlaveTemplate.setRetentionStrategy(new DockerOnceRetentionStrategy(30)); final ArrayList<DockerSlaveTemplate> dockerSlaveTemplates = new ArrayList<>(); dockerSlaveTemplates.add(dockerSlaveTemplate); before = new DockerCloud("docker-cloud", dockerSlaveTemplates, 17, connector); j.getInstance().clouds.add(before); j.getInstance().save(); j.configRoundtrip(); after = (DockerCloud) j.getInstance().getCloud("docker-cloud"); }
Example #11
Source File: AbstractGitTestCase.java From flaky-test-handler-plugin with Apache License 2.0 | 4 votes |
protected void setVariables(Node node, EnvironmentVariablesNodeProperty.Entry... entries) throws IOException { node.getNodeProperties().replaceBy( Collections.singleton(new EnvironmentVariablesNodeProperty( entries))); }