Package com.groupon.jenkins.buildtype.util.shell

Examples of com.groupon.jenkins.buildtype.util.shell.ShellCommands


    public void should_support_nested_links(){
        DockerImageBuildConfiguration dockerImageBuildConfiguration = new DockerImageBuildConfiguration(of("image", "ubutu",
                "links",  asList(of("image","mysql",
                                     "links", asList(of("image","redis"))
                                 )),
                "command", "echo success"),"buildId", new ShellCommands());
        ShellCommands shellCommands = dockerImageBuildConfiguration.toShellCommands(null);
        Assert.assertEquals("docker run -d --name redis_buildId redis",shellCommands.get(0));
        Assert.assertEquals("docker run -d --name mysql_buildId --link redis_buildId:redis mysql",shellCommands.get(1));
        Assert.assertEquals("docker run --rm --sig-proxy=true --link mysql_buildId:mysql ubutu sh -cx \"echo success\"",shellCommands.get(2));
        Assert.assertEquals("docker kill  mysql_buildId",shellCommands.get(3));
        Assert.assertEquals("docker rm  mysql_buildId",shellCommands.get(4));
        Assert.assertEquals("docker kill  redis_buildId",shellCommands.get(5));
        Assert.assertEquals("docker rm  redis_buildId",shellCommands.get(6));

    }
View Full Code Here


               buildId,
           checkoutCommands);
    }

    public ShellCommands toShellCommands(Combination combination) {
        ShellCommands shellCommands = new ShellCommands();
        DockerCommandBuilder dockerRunCommand = dockerCommand("run")
                .flag("rm")
                .flag("sig-proxy=true")
               .bulkOptions(config.get("run_params", String.class))
                .args(getImageName(), "sh -cx \"" + getRunCommand(combination) + "\"");

         shellCommands.addAll(linkServicesToRunCommand(dockerRunCommand, config.get("links", List.class)));

         shellCommands.addAll(linkCleanupCommands);

        return shellCommands;
    }
View Full Code Here

public class CheckoutCommands {
    public static ShellCommands get(Map<String, String> dotCiEnvVars) {
        GitUrl gitRepoUrl = new GitUrl(dotCiEnvVars.get("GIT_URL"));
        String gitUrl = gitRepoUrl.getHttpsUrl();
        String checkoutLocation = format("/var/%s",gitRepoUrl.getFullRepoName());
        ShellCommands shellCommands = new ShellCommands();
        if(dotCiEnvVars.get("DOTCI_PULL_REQUEST") != null){
            shellCommands.add(format("git clone  --depth=50 %s %s",gitUrl,checkoutLocation));
            shellCommands.add("cd " + checkoutLocation);
            shellCommands.add(format("git fetch origin \"+refs/pull/%s/merge:\"", dotCiEnvVars.get("DOTCI_PULL_REQUEST")));
            shellCommands.add("git reset --hard FETCH_HEAD");
        }else {
            shellCommands.add(format("git clone  --branch=%s %s %s", dotCiEnvVars.get("DOTCI_BRANCH"), gitUrl,checkoutLocation));
            shellCommands.add("cd " + checkoutLocation);
            shellCommands.add(format("git reset --hard  %s", dotCiEnvVars.get("SHA")));
        }
        return shellCommands;
    }
View Full Code Here

            plugin.perform(dynamicBuild, launcher, listener);
        }
    }

    private Result runBuildCombination(Combination combination,BuildExecutionContext buildExecutionContext, BuildListener listener) throws IOException, InterruptedException {
        ShellCommands mainBuildScript = buildConfiguration.toScript(combination);
        return new ShellScriptRunner(buildExecutionContext,listener).runScript(mainBuildScript);
    }
View Full Code Here

            }
            return result;

        }catch (InterruptedException e){
            if(buildConfiguration !=null && Iterables.isEmpty(buildConfiguration.getLinkCleanupCommands())){
                ShellCommands cleanupCommands = new ShellCommands();
                cleanupCommands.addAll(buildConfiguration.getLinkCleanupCommands());
                new ShellScriptRunner(buildExecutionContext, listener).runScript(cleanupCommands);
            }
           throw e;
        }
    }
View Full Code Here

                buildId,
                checkoutCommands);
    }

    public ShellCommands toShellCommands(Combination combination) {
        ShellCommands shellCommands = new ShellCommands();
        DockerCommandBuilder dockerRunCommand = dockerCommand("run")
                .flag("rm")
                .flag("sig-proxy=true")
                .flag("v", "/usr/bin/docker:/bin/docker")
                .flag("v","/var/run/docker.sock:/docker.sock")
                .flag("e", "DOCKER_HOST=\"unix:///docker.sock\"")
                .args(getImageName(), "sh -cx \"" + getRunCommand(combination) + "\"");

        //shellCommands.addAll(linkServicesToRunCommand(dockerRunCommand, config.get("links", List.class)));

        //shellCommands.addAll(linkCleanupCommands);
        shellCommands.add(dockerRunCommand.get());

        return shellCommands;
    }
View Full Code Here

    }

    @Override
    protected String getRunCommand(Combination combination) {
        String buildImageCommand = dockerCommand("build").flag("t","dockerfile" ).args( ".").get();
        ShellCommands buildCommands = new ShellCommands();
        buildCommands.add(buildImageCommand);
        String buildCommand =  new ShellCommands(getCommandForCombination(combination)).toSingleShellCommand();
        String buildShellCommand = "sh -cx '" +  buildCommand+ "'";
        DockerCommandBuilder dockerRunCommand = dockerCommand("run")
                .flag("rm")
                .flag("sig-proxy=true")
                .bulkOptions(config.get("run_params", String.class))
                .args("dockerfile", buildShellCommand);
        buildCommands.addAll(linkServicesToRunCommand(dockerRunCommand, config.get("links", List.class)));
        return checkoutCommands.add(buildCommands).toSingleShellCommand();
    }
View Full Code Here

        return getConfigValue().isMap();
    }

    @Override
    public ShellCommands toScript(Combination combination) {
        return new ShellCommands(getShellCommands(combination));
    }
View Full Code Here

    }

    protected String getRunCommand(Combination combination) {
        List commands = getCommandForCombination(combination);

        return checkoutCommands.add(new ShellCommands(commands)).toSingleShellCommand();
    }
View Full Code Here

public class VarsSectionTest {

    @Test
    public void should_export_environment_variables() {
        VarsSection varsSection = new VarsSection(new MapValue<String, String>(map("RBXOPT", "-X19", "JRUBY_OPTS", "--1.9")));
        ShellCommands script = varsSection.toScript(new Combination(map("script", "main")));
        assertTrue(script.toShellScript().contains("export RBXOPT=-X19"));
        assertTrue(script.toShellScript().contains("export JRUBY_OPTS=--1.9"));
    }
View Full Code Here

TOP

Related Classes of com.groupon.jenkins.buildtype.util.shell.ShellCommands

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.