|
29 | 29 | import com.gpuopenanalytics.jenkins.remotedocker.config.ConfigItem; |
30 | 30 | import com.gpuopenanalytics.jenkins.remotedocker.config.VolumeConfiguration; |
31 | 31 | import hudson.Extension; |
| 32 | +import hudson.Launcher; |
32 | 33 | import hudson.model.AbstractBuild; |
33 | 34 | import hudson.model.Descriptor; |
34 | 35 | import hudson.util.ArgumentListBuilder; |
35 | 36 | import org.apache.commons.lang.StringUtils; |
36 | 37 | import org.kohsuke.stapler.DataBoundConstructor; |
37 | 38 |
|
38 | 39 | import javax.annotation.Nonnull; |
| 40 | +import java.io.IOException; |
39 | 41 | import java.util.List; |
40 | 42 |
|
41 | 43 | /** |
@@ -80,17 +82,28 @@ public void validate() throws Descriptor.FormException { |
80 | 82 |
|
81 | 83 | @Override |
82 | 84 | public void setupImage(DockerLauncher launcher, |
83 | | - String localWorkspace) { |
84 | | - //No-op |
| 85 | + String localWorkspace) throws IOException, InterruptedException { |
| 86 | + if (isForcePull()) { |
| 87 | + ArgumentListBuilder args = new ArgumentListBuilder(); |
| 88 | + String image = Utils.resolveVariables(launcher.getBuild(), |
| 89 | + getImage()); |
| 90 | + args.add("docker", "pull", image); |
| 91 | + Launcher.ProcStarter proc = launcher.executeCommand(args) |
| 92 | + .stderr(launcher.getListener().getLogger()); |
| 93 | + if (launcher.isDebug()) { |
| 94 | + proc = proc.stdout(launcher.getListener()); |
| 95 | + } |
| 96 | + int status = proc.join(); |
| 97 | + if (status != 0) { |
| 98 | + throw new IOException("Could not pull image: " + image); |
| 99 | + } |
| 100 | + } |
85 | 101 | } |
86 | 102 |
|
87 | 103 | @Override |
88 | 104 | public void addCreateArgs(DockerLauncher launcher, |
89 | 105 | ArgumentListBuilder args, |
90 | 106 | AbstractBuild build) { |
91 | | - if (isForcePull()) { |
92 | | - args.add("--pull"); |
93 | | - } |
94 | 107 | getConfigItemList().stream() |
95 | 108 | .forEach(item -> item.addCreateArgs(launcher, args, build)); |
96 | 109 | getVolumes().stream() |
|
0 commit comments