Search in sources :

Example 1 with NodeProperty

use of hudson.slaves.NodeProperty in project workflow-job-plugin by jenkinsci.

the class WorkflowRunTest method globalNodePropertiesInEnv.

@Test
@Issue("JENKINS-43396")
public void globalNodePropertiesInEnv() throws Exception {
    DescribableList<NodeProperty<?>, NodePropertyDescriptor> original = r.jenkins.getGlobalNodeProperties();
    EnvironmentVariablesNodeProperty envProp = new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("KEY", "VALUE"));
    original.add(envProp);
    WorkflowJob j = r.jenkins.createProject(WorkflowJob.class, "envVars");
    j.setDefinition(new CpsFlowDefinition("echo \"KEY is ${env.KEY}\"", true));
    WorkflowRun b = r.assertBuildStatusSuccess(j.scheduleBuild2(0));
    r.assertLogContains("KEY is " + envProp.getEnvVars().get("KEY"), b);
}
Also used : NodePropertyDescriptor(hudson.slaves.NodePropertyDescriptor) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) NodeProperty(hudson.slaves.NodeProperty) EnvironmentVariablesNodeProperty(hudson.slaves.EnvironmentVariablesNodeProperty) EnvironmentVariablesNodeProperty(hudson.slaves.EnvironmentVariablesNodeProperty) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 2 with NodeProperty

use of hudson.slaves.NodeProperty in project workflow-job-plugin by jenkinsci.

the class WorkflowRun method getEnvironment.

@Override
public EnvVars getEnvironment(TaskListener listener) throws IOException, InterruptedException {
    EnvVars env = super.getEnvironment(listener);
    Jenkins instance = Jenkins.getInstance();
    if (instance != null) {
        for (NodeProperty nodeProperty : instance.getGlobalNodeProperties()) {
            nodeProperty.buildEnvVars(env, listener);
        }
    }
    // TODO EnvironmentContributingAction does not support Job yet:
    ParametersAction a = getAction(ParametersAction.class);
    if (a != null) {
        for (ParameterValue v : a) {
            v.buildEnvironment(this, env);
        }
    }
    EnvVars.resolve(env);
    return env;
}
Also used : Jenkins(jenkins.model.Jenkins) EnvVars(hudson.EnvVars) ParameterValue(hudson.model.ParameterValue) NodeProperty(hudson.slaves.NodeProperty) ParametersAction(hudson.model.ParametersAction)

Example 3 with NodeProperty

use of hudson.slaves.NodeProperty in project configuration-as-code-plugin by jenkinsci.

the class JenkinsConfiguratorTest method shouldSetEnvironmentVariable.

@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"));
}
Also used : EnvVars(hudson.EnvVars) NodePropertyDescriptor(hudson.slaves.NodePropertyDescriptor) NodeProperty(hudson.slaves.NodeProperty) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 4 with NodeProperty

use of hudson.slaves.NodeProperty in project configuration-as-code-plugin by jenkinsci.

the class GlobalNodePropertiesTest method configure.

@Test
public void configure() {
    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());
}
Also used : Jenkins(jenkins.model.Jenkins) NodePropertyDescriptor(hudson.slaves.NodePropertyDescriptor) EnvironmentVariablesNodeProperty(hudson.slaves.EnvironmentVariablesNodeProperty) NodeProperty(hudson.slaves.NodeProperty) Util.toYamlString(io.jenkins.plugins.casc.misc.Util.toYamlString) Map(java.util.Map) Test(org.junit.Test)

Aggregations

NodeProperty (hudson.slaves.NodeProperty)4 NodePropertyDescriptor (hudson.slaves.NodePropertyDescriptor)3 Test (org.junit.Test)3 EnvVars (hudson.EnvVars)2 EnvironmentVariablesNodeProperty (hudson.slaves.EnvironmentVariablesNodeProperty)2 Jenkins (jenkins.model.Jenkins)2 Issue (org.jvnet.hudson.test.Issue)2 ParameterValue (hudson.model.ParameterValue)1 ParametersAction (hudson.model.ParametersAction)1 ConfiguredWithCode (io.jenkins.plugins.casc.misc.ConfiguredWithCode)1 Util.toYamlString (io.jenkins.plugins.casc.misc.Util.toYamlString)1 Map (java.util.Map)1 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)1