Java Code Examples for hudson.util.ArgumentListBuilder#addTokenized()
The following examples show how to use
hudson.util.ArgumentListBuilder#addTokenized() .
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: WindowsDockerClient.java From docker-workflow-plugin with MIT License | 5 votes |
@Override public String run(@Nonnull EnvVars launchEnv, @Nonnull String image, @CheckForNull String args, @CheckForNull String workdir, @Nonnull Map<String, String> volumes, @Nonnull Collection<String> volumesFromContainers, @Nonnull EnvVars containerEnv, @Nonnull String user, @Nonnull String... command) throws IOException, InterruptedException { ArgumentListBuilder argb = new ArgumentListBuilder("docker", "run", "-d", "-t"); if (args != null) { argb.addTokenized(args); } if (workdir != null) { argb.add("-w", workdir); } for (Map.Entry<String, String> volume : volumes.entrySet()) { argb.add("-v", volume.getKey() + ":" + volume.getValue()); } for (String containerId : volumesFromContainers) { argb.add("--volumes-from", containerId); } for (Map.Entry<String, String> variable : containerEnv.entrySet()) { argb.add("-e"); argb.addMasked(variable.getKey()+"="+variable.getValue()); } argb.add(image).add(command); LaunchResult result = launch(launchEnv, false, null, argb); if (result.getStatus() == 0) { return result.getOut(); } else { throw new IOException(String.format("Failed to run image '%s'. Error: %s", image, result.getErr())); } }
Example 2
Source File: DockerClient.java From docker-workflow-plugin with MIT License | 5 votes |
/** * Run a docker image. * * @param launchEnv Docker client launch environment. * @param image The image name. * @param args Any additional arguments for the {@code docker run} command. * @param workdir The working directory in the container, or {@code null} for default. * @param volumes Volumes to be bound. Supply an empty list if no volumes are to be bound. * @param volumesFromContainers Mounts all volumes from the given containers. * @param containerEnv Environment variables to set in container. * @param user The <strong>uid:gid</strong> to execute the container command as. Use {@link #whoAmI()}. * @param command The command to execute in the image container being run. * @return The container ID. */ public String run(@Nonnull EnvVars launchEnv, @Nonnull String image, @CheckForNull String args, @CheckForNull String workdir, @Nonnull Map<String, String> volumes, @Nonnull Collection<String> volumesFromContainers, @Nonnull EnvVars containerEnv, @Nonnull String user, @Nonnull String... command) throws IOException, InterruptedException { ArgumentListBuilder argb = new ArgumentListBuilder(); argb.add("run", "-t", "-d"); // Username might be empty because we are running on Windows if (StringUtils.isNotEmpty(user)) { argb.add("-u", user); } if (args != null) { argb.addTokenized(args); } if (workdir != null) { argb.add("-w", workdir); } for (Map.Entry<String, String> volume : volumes.entrySet()) { argb.add("-v", volume.getKey() + ":" + volume.getValue() + ":rw,z"); } for (String containerId : volumesFromContainers) { argb.add("--volumes-from", containerId); } for (Map.Entry<String, String> variable : containerEnv.entrySet()) { argb.add("-e"); argb.addMasked(variable.getKey()+"="+variable.getValue()); } argb.add(image).add(command); LaunchResult result = launch(launchEnv, false, null, argb); if (result.getStatus() == 0) { return result.getOut(); } else { throw new IOException(String.format("Failed to run image '%s'. Error: %s", image, result.getErr())); } }
Example 3
Source File: AbstractAnsibleInvocation.java From ansible-plugin with Apache License 2.0 | 4 votes |
public ArgumentListBuilder appendAdditionalParameters(ArgumentListBuilder args) { args.addTokenized(envVars.expand(additionalParameters)); return args; }