Search in sources :

Example 6 with CaptureEnvironmentBuilder

use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project jenkins by jenkinsci.

the class SimpleBuildWrapperTest method envOverrideExpand.

@Test
public void envOverrideExpand() throws Exception {
    Assume.assumeFalse(Functions.isWindows());
    FreeStyleProject p = r.createFreeStyleProject();
    p.getBuildWrappersList().add(new WrapperWithEnvOverrideExpand());
    SpecialEnvSlave slave = new SpecialEnvSlave(tmp.getRoot(), r.createComputerLauncher(null));
    r.jenkins.addNode(slave);
    p.setAssignedNode(slave);
    JDK jdk = new JDK("test", "/opt/jdk");
    r.jenkins.getJDKs().add(jdk);
    p.setJDK(jdk);
    CaptureEnvironmentBuilder captureEnvironment = new CaptureEnvironmentBuilder();
    p.getBuildersList().add(captureEnvironment);
    p.getBuildersList().add(new Shell("echo effective PATH=$PATH"));
    FreeStyleBuild b = r.buildAndAssertSuccess(p);
    String expected = "/home/jenkins/extra/bin:/opt/jdk/bin:/usr/bin:/bin";
    assertEquals(expected, captureEnvironment.getEnvVars().get("PATH"));
    // TODO why is /opt/jdk/bin added twice? In CommandInterpreter.perform, envVars right before Launcher.launch is correct, but this somehow sneaks in.
    r.assertLogContains("effective PATH=/opt/jdk/bin:" + expected, b);
}
Also used : JDK(hudson.model.JDK) Shell(hudson.tasks.Shell) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder) Test(org.junit.Test)

Example 7 with CaptureEnvironmentBuilder

use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project jenkins by jenkinsci.

the class BuiltInNodeMigrationTest method assertStatus.

public static void assertStatus(JenkinsRule j, boolean migrationDoneGetterValue, Boolean migrationNeededFieldValue, String label, String nodeName) throws Exception {
    assertEquals(migrationDoneGetterValue, j.jenkins.getRenameMigrationDone());
    assertEquals(migrationNeededFieldValue, j.jenkins.nodeRenameMigrationNeeded);
    assertEquals(new LabelAtom(label), j.jenkins.getSelfLabel());
    final FreeStyleProject freeStyleProject = j.createFreeStyleProject();
    final CaptureEnvironmentBuilder environmentBuilder = new CaptureEnvironmentBuilder();
    freeStyleProject.getBuildersList().add(environmentBuilder);
    j.buildAndAssertSuccess(freeStyleProject);
    assertEquals(nodeName, environmentBuilder.getEnvVars().get("NODE_NAME"));
}
Also used : LabelAtom(hudson.model.labels.LabelAtom) FreeStyleProject(hudson.model.FreeStyleProject) CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder)

Example 8 with CaptureEnvironmentBuilder

use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project jenkins by jenkinsci.

the class EnvironmentContributorTest method projectScoped.

/**
 * Makes sure that the project-scoped environment variables are getting
 * consulted.
 */
@Test
public void projectScoped() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject();
    CaptureEnvironmentBuilder c = new CaptureEnvironmentBuilder();
    p.getBuildersList().add(c);
    p.setDescription("Issac Newton");
    j.buildAndAssertSuccess(p);
    assertEquals("Issac Newton", c.getEnvVars().get("ABC"));
    assertEquals("built-in", c.getEnvVars().get("NODE_NAME"));
}
Also used : CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder) Test(org.junit.Test)

Example 9 with CaptureEnvironmentBuilder

use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project jenkins by jenkinsci.

the class ParametersTest method sensitiveParameters.

@Test
public void sensitiveParameters() throws Exception {
    FreeStyleProject project = j.createFreeStyleProject();
    ParametersDefinitionProperty pdb = new ParametersDefinitionProperty(new PasswordParameterDefinition("password", "12345", "password description"));
    project.addProperty(pdb);
    CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder();
    project.getBuildersList().add(builder);
    FreeStyleBuild build = j.buildAndAssertSuccess(project);
    Set<String> sensitiveVars = build.getSensitiveBuildVariables();
    assertNotNull(sensitiveVars);
    assertTrue(sensitiveVars.contains("password"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder) Test(org.junit.Test)

Example 10 with CaptureEnvironmentBuilder

use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project jenkins by jenkinsci.

the class ParametersTest method nonSensitiveParameters.

@Test
public void nonSensitiveParameters() throws Exception {
    FreeStyleProject project = j.createFreeStyleProject();
    ParametersDefinitionProperty pdb = new ParametersDefinitionProperty(new StringParameterDefinition("string", "defaultValue", "string description"));
    project.addProperty(pdb);
    CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder();
    project.getBuildersList().add(builder);
    FreeStyleBuild build = j.buildAndAssertSuccess(project);
    Set<String> sensitiveVars = build.getSensitiveBuildVariables();
    assertNotNull(sensitiveVars);
    assertFalse(sensitiveVars.contains("string"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder) Test(org.junit.Test)

Aggregations

CaptureEnvironmentBuilder (org.jvnet.hudson.test.CaptureEnvironmentBuilder)19 Test (org.junit.Test)17 FreeStyleProject (hudson.model.FreeStyleProject)5 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)3 UserCause (hudson.model.Cause.UserCause)3 FreeStyleBuild (hudson.model.FreeStyleBuild)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Issue (org.jvnet.hudson.test.Issue)3 WebClient (org.jvnet.hudson.test.JenkinsRule.WebClient)3 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)2 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)2 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)2 FileWriteBuilder (hudson.plugins.copyartifact.testutils.FileWriteBuilder)2 ArtifactArchiver (hudson.tasks.ArtifactArchiver)2 WebClientOptions (com.gargoylesoftware.htmlunit.WebClientOptions)1 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)1 HtmlCheckBoxInput (com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput)1 HtmlOption (com.gargoylesoftware.htmlunit.html.HtmlOption)1 HtmlSelect (com.gargoylesoftware.htmlunit.html.HtmlSelect)1 HtmlTextInput (com.gargoylesoftware.htmlunit.html.HtmlTextInput)1