Skip to content
Permalink
Browse files

[JENKINS-23025] Allow container IDs contain env. variables

  • Loading branch information
vjuranek committed May 18, 2014
1 parent 2a458c7 commit d1e4d11cf10dec845c3941eec3f80546969640db
@@ -7,6 +7,7 @@

import org.jenkinsci.plugins.dockerbuildstep.action.EnvInvisibleAction;
import org.jenkinsci.plugins.dockerbuildstep.log.ConsoleLogger;
import org.jenkinsci.plugins.dockerbuildstep.util.Resolver;
import org.kohsuke.stapler.DataBoundConstructor;

import com.kpelykh.docker.client.DockerClient;
@@ -41,6 +42,8 @@ public void execute(@SuppressWarnings("rawtypes") AbstractBuild build, ConsoleLo
throw new IllegalArgumentException("At least one parameter is required");
}

imageId = Resolver.buildVar(build, imageId);

DockerClient client = getClient();
List<Container> containers = getClient().listContainers(true);
for (Container c : containers) {
@@ -10,6 +10,7 @@
import org.jenkinsci.plugins.dockerbuildstep.action.EnvInvisibleAction;
import org.jenkinsci.plugins.dockerbuildstep.log.ConsoleLogger;
import org.jenkinsci.plugins.dockerbuildstep.util.PortUtils;
import org.jenkinsci.plugins.dockerbuildstep.util.Resolver;
import org.kohsuke.stapler.DataBoundConstructor;

import com.kpelykh.docker.client.DockerClient;
@@ -51,6 +52,8 @@ public void execute(@SuppressWarnings("rawtypes") AbstractBuild build, ConsoleLo
throw new IllegalArgumentException("At least one parameter is required");
}

containerIds = Resolver.buildVar(build, containerIds);

List<String> ids = Arrays.asList(containerIds.split(","));
DockerClient client = getClient();
//TODO check, if container exists and is stopped (probably catch exception)
@@ -6,6 +6,7 @@
import java.util.List;

import org.jenkinsci.plugins.dockerbuildstep.log.ConsoleLogger;
import org.jenkinsci.plugins.dockerbuildstep.util.Resolver;
import org.kohsuke.stapler.DataBoundConstructor;

import com.kpelykh.docker.client.DockerClient;
@@ -38,6 +39,8 @@ public void execute(@SuppressWarnings("rawtypes") AbstractBuild build, ConsoleLo
throw new IllegalArgumentException("At least one parameter is required");
}

imageId = Resolver.buildVar(build, imageId);

DockerClient client = getClient();
List<Container> containers = getClient().listContainers(false);
for (Container c : containers) {
@@ -7,6 +7,7 @@
import java.util.List;

import org.jenkinsci.plugins.dockerbuildstep.log.ConsoleLogger;
import org.jenkinsci.plugins.dockerbuildstep.util.Resolver;
import org.kohsuke.stapler.DataBoundConstructor;

import com.kpelykh.docker.client.DockerClient;
@@ -40,6 +41,8 @@ public void execute(@SuppressWarnings("rawtypes") AbstractBuild build, ConsoleLo
throw new IllegalArgumentException("At least one parameter is required");
}

containerIds = Resolver.buildVar(build, containerIds);

List<String> ids = Arrays.asList(containerIds.split(","));
DockerClient client = getClient();
//TODO check, if container is actually running
@@ -0,0 +1,25 @@
package org.jenkinsci.plugins.dockerbuildstep.util;

import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.util.VariableResolver;

/**
* Convenient class for resolving/expanding various variabales.
*
* @author vjuranek
*
*/
public class Resolver {

public static String buildVar(final AbstractBuild<?, ?> build,final String toResolve) {
VariableResolver<String> vr = build.getBuildVariableResolver();
String resolved = Util.replaceMacro(toResolve, vr);
try {
resolved = build.getEnvironment().expand(resolved); //TODO avoid deprecated method
} catch (Exception e) {
//TODO no-op?
}
return resolved;
}
}

0 comments on commit d1e4d11

Please sign in to comment.
You can’t perform that action at this time.