public void set() throws IOException { List<EnvironmentVariablesNodeProperty.Entry> entries = new ArrayList<>(env.size()); for (Map.Entry<String, String> entry : env.entrySet()) { entries.add(new EnvironmentVariablesNodeProperty.Entry(entry.getKey(), entry.getValue())); } EnvironmentVariablesNodeProperty newProperty = new EnvironmentVariablesNodeProperty(entries); DescribableList<NodeProperty<?>, NodePropertyDescriptor> nodeProperties = agent.getNodeProperties(); nodeProperties.replace(newProperty); }
public JCloudsSlave( @Nonnull ProvisioningActivity.Id id, @Nonnull Server metadata, @Nonnull String labelString, @Nonnull SlaveOptions slaveOptions ) throws IOException, Descriptor.FormException { super( metadata.getName(), null, slaveOptions.getFsRoot(), slaveOptions.getNumExecutors(), Mode.NORMAL, labelString, null, new JCloudsRetentionStrategy(), Collections.singletonList(new EnvironmentVariablesNodeProperty( new EnvironmentVariablesNodeProperty.Entry("OPENSTACK_PUBLIC_IP", Openstack.getPublicAddress(metadata)) )) ); this.cloudName = id.getCloudName(); // TODO deprecate field this.provisioningId = id; this.options = slaveOptions; this.nodeId = metadata.getId(); this.cache = makeCache(); setLauncher(new JCloudsLauncher(getLauncherFactory().createLauncher(this))); }
? new AzureVMAgentSSHLauncher() : new JNLPLauncher(), retentionStrategy, Arrays.asList(new EnvironmentVariablesNodeProperty( new EnvironmentVariablesNodeProperty.Entry("FQDN", fqdn) )),
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); }
@Before public void configureCloud() throws Exception { cloud = setupCloud(this); createSecret(cloud.connect()); cloud.getTemplates().clear(); cloud.addTemplate(buildBusyboxTemplate("busybox")); // Agents running in Kubernetes (minikube) need to connect to this server, so localhost does not work URL url = r.getURL(); String hostAddress = System.getProperty("jenkins.host.address"); if (hostAddress == null) { hostAddress = InetAddress.getLocalHost().getHostAddress(); } URL nonLocalhostUrl = new URL(url.getProtocol(), hostAddress, url.getPort(), url.getFile()); JenkinsLocationConfiguration.get().setUrl(nonLocalhostUrl.toString()); 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(); }
@BeforeClass public static void setUpAgent() throws Exception { s = j.createOnlineSlave(); s.setNumExecutors(4); s.setLabelString("some-label docker test"); s.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("ONAGENT", "true"))); }
@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); } }
@BeforeClass public static void setUpAgentAndCreds() throws Exception { s = j.createOnlineSlave(); s.setLabelString("some-label docker here"); 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"))); CredentialsStore store = CredentialsProvider.lookupStores(j.jenkins).iterator().next(); String usernamePasswordCredentialsId = "FOOcredentials"; UsernamePasswordCredentialsImpl usernamePassword = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, usernamePasswordCredentialsId, "sample", usernamePasswordUsername, usernamePasswordPassword); store.addCredentials(Domain.global(), usernamePassword); }
@BeforeClass public static void setUpAgent() throws Exception { s = j.createOnlineSlave(); s.setLabelString("some-label docker"); s.getNodeProperties().add( new EnvironmentVariablesNodeProperty( new EnvironmentVariablesNodeProperty.Entry("HAS_BACKSLASHES", "C:\\Windows"), new EnvironmentVariablesNodeProperty.Entry("FOO", "OTHER"))); }
@Issue("JENKINS-53734") @Test public void parallelStagesNestedInSequential() throws Exception { Slave s = j.createOnlineSlave(); s.setLabelString("first-agent"); s.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("WHICH_AGENT", "first agent"))); Slave s2 = j.createOnlineSlave(); s2.setLabelString("second-agent"); s2.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("WHICH_AGENT", "second agent"))); expect("parallelStagesNestedInSequential") .logContains("[Pipeline] { (foo)", "First stage, first agent", "[Pipeline] { (inner-first)", "Second stage, second agent", "Apache Maven 3.0.1", "[Pipeline] { (inner-second)") .logNotContains("WE SHOULD NEVER GET HERE") .go(); }
@Issue("JENKINS-41334") @Test public void parallelStagesAgentEnvWhen() throws Exception { Slave s = j.createOnlineSlave(); s.setLabelString("first-agent"); s.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("WHICH_AGENT", "first agent"))); Slave s2 = j.createOnlineSlave(); s2.setLabelString("second-agent"); s2.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("WHICH_AGENT", "second agent"))); expect("parallelStagesAgentEnvWhen") .logContains("[Pipeline] { (foo)", "{ (Branch: first)", "{ (Branch: second)", "First stage, first agent", "First stage, do not override", "First stage, overrode once and done", "First stage, overrode twice, in first branch", "First stage, overrode per nested, in first branch", "First stage, declared per nested, in first branch", "Second stage, second agent", "Second stage, do not override", "Second stage, overrode once and done", "Second stage, overrode twice, in second branch", "Second stage, overrode per nested, in second branch", "Second stage, declared per nested, in second branch", "Apache Maven 3.0.1") .logNotContains("WE SHOULD NEVER GET HERE") .go(); }
/** * This test aims to verify that the environment variables (from Global Properties section) are available in SCM * Polling. */ @Ignore("TODO org.tmatesoft.svn.core.SVNException: svn: E175002: PROPFIND of '/trunk/jenkins/test-projects/model-maven-project': 405 Method Not Allowed (https://svn.jenkins-ci.org)") @Issue("JENKINS-31067") @Test public void pollingWithEnvVars() throws Exception { jenkins.getInstance().getGlobalNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("BRANCH", "trunk"))); FreeStyleProject project = jenkins.createFreeStyleProject(); project.setScm(new SubversionSCM(REPO_URL)); jenkins.assertBuildStatusSuccess(project.scheduleBuild2(0).get()); TaskListener listener = jenkins.createTaskListener(); PollingResult poll = project.poll(listener); assertFalse(poll.hasChanges()); } }
DumbSlave s = story.j.createOnlineSlave(); s.setLabelString("remote quick"); s.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("ONAGENT", "true")));
Slave s = j.createOnlineSlave(); s.setLabelString("first-agent"); s.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("WHICH_AGENT", "first agent"))); s2.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("WHICH_AGENT", "second agent")));