Skip to content

Commit cf80d9e

Browse files
authored
Merge pull request jenkinsci#133 from jglick/login-JENKINS-38018
[JENKINS-38018] Use docker-login wherever possible for registry credentials
2 parents 88211b9 + 6653988 commit cf80d9e

File tree

5 files changed

+58
-17
lines changed

5 files changed

+58
-17
lines changed

pom.xml

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.jenkins-ci.plugins</groupId>
66
<artifactId>plugin</artifactId>
7-
<version>2.21</version>
7+
<version>3.3</version>
88
<relativePath />
99
</parent>
1010
<artifactId>docker-workflow</artifactId>
@@ -16,11 +16,11 @@
1616
<licenses>
1717
<license>
1818
<name>MIT License</name>
19-
<url>http://opensource.org/licenses/MIT</url>
19+
<url>https://opensource.org/licenses/MIT</url>
2020
</license>
2121
</licenses>
2222

23-
<url>http://wiki.jenkins-ci.org/display/JENKINS/Docker+Pipeline+Plugin</url>
23+
<url>https://wiki.jenkins.io/display/JENKINS/Docker+Pipeline+Plugin</url>
2424
<scm>
2525
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
2626
<developerConnection>scm:git:[email protected]:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
@@ -29,7 +29,11 @@
2929
</scm>
3030

3131
<properties>
32-
<jenkins.version>1.642.3</jenkins.version>
32+
<jenkins.version>2.60.3</jenkins.version>
33+
<java.level>8</java.level>
34+
<workflow-step-api-plugin.version>2.9</workflow-step-api-plugin.version>
35+
<workflow-support-plugin.version>2.12</workflow-support-plugin.version>
36+
<hpi-plugin.version>2.2</hpi-plugin.version> <!-- TODO pending https://github.com/jenkinsci/plugin-pom/pull/94 -->
3337
</properties>
3438
<repositories>
3539
<repository>
@@ -47,7 +51,7 @@
4751
<dependency>
4852
<groupId>org.jenkins-ci.plugins</groupId>
4953
<artifactId>docker-commons</artifactId>
50-
<version>1.5</version>
54+
<version>1.12-20180131.190257-1</version> <!-- TODO https://github.com/jenkinsci/docker-commons-plugin/pull/67 -->
5155
</dependency>
5256
<dependency>
5357
<groupId>org.jenkins-ci.plugins.workflow</groupId>
@@ -59,18 +63,43 @@
5963
<artifactId>workflow-durable-task-step</artifactId>
6064
<version>2.8</version>
6165
</dependency>
66+
<dependency>
67+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
68+
<artifactId>workflow-basic-steps</artifactId>
69+
<version>2.3</version>
70+
</dependency>
71+
<dependency>
72+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
73+
<artifactId>workflow-api</artifactId>
74+
<version>2.8</version>
75+
</dependency>
76+
<dependency>
77+
<groupId>org.jenkins-ci.plugins</groupId>
78+
<artifactId>script-security</artifactId>
79+
<version>1.25</version>
80+
</dependency>
81+
<dependency>
82+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
83+
<artifactId>workflow-step-api</artifactId>
84+
<version>${workflow-step-api-plugin.version}</version>
85+
</dependency>
86+
<dependency> <!-- SemaphoreStep -->
87+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
88+
<artifactId>workflow-support</artifactId>
89+
<version>${workflow-support-plugin.version}</version>
90+
</dependency>
6291
<dependency> <!-- StepConfigTester -->
6392
<groupId>org.jenkins-ci.plugins.workflow</groupId>
6493
<artifactId>workflow-step-api</artifactId>
94+
<version>${workflow-step-api-plugin.version}</version>
6595
<classifier>tests</classifier>
66-
<version>2.7</version>
6796
<scope>test</scope>
6897
</dependency>
6998
<dependency> <!-- SemaphoreStep -->
7099
<groupId>org.jenkins-ci.plugins.workflow</groupId>
71100
<artifactId>workflow-support</artifactId>
101+
<version>${workflow-support-plugin.version}</version>
72102
<classifier>tests</classifier>
73-
<version>2.12</version>
74103
<scope>test</scope>
75104
</dependency>
76105
<dependency>
@@ -79,16 +108,10 @@
79108
<version>2.9</version>
80109
<scope>test</scope>
81110
</dependency>
82-
<dependency>
83-
<groupId>org.jenkins-ci.plugins.workflow</groupId>
84-
<artifactId>workflow-basic-steps</artifactId>
85-
<version>2.3</version>
86-
<scope>test</scope>
87-
</dependency>
88111
<dependency>
89112
<groupId>org.jenkins-ci.plugins</groupId>
90113
<artifactId>credentials-binding</artifactId>
91-
<version>1.7</version>
114+
<version>1.12</version>
92115
<scope>test</scope>
93116
</dependency>
94117
<dependency>

src/main/java/org/jenkinsci/plugins/docker/workflow/RegistryEndpointStep.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,29 @@
2424
package org.jenkinsci.plugins.docker.workflow;
2525

2626
import com.google.inject.Inject;
27+
import hudson.EnvVars;
2728
import hudson.Extension;
2829
import hudson.FilePath;
2930
import hudson.Launcher;
3031
import hudson.model.Job;
32+
import hudson.model.Node;
3133
import hudson.model.TaskListener;
3234
import java.io.IOException;
35+
import javax.annotation.CheckForNull;
3336
import javax.annotation.Nonnull;
3437
import org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint;
3538
import org.jenkinsci.plugins.docker.commons.credentials.KeyMaterialFactory;
39+
import org.jenkinsci.plugins.docker.commons.tools.DockerTool;
3640
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
3741
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
3842
import org.jenkinsci.plugins.workflow.steps.StepContextParameter;
3943
import org.kohsuke.stapler.DataBoundConstructor;
44+
import org.kohsuke.stapler.DataBoundSetter;
4045

4146
public class RegistryEndpointStep extends AbstractStepImpl {
4247

4348
private final @Nonnull DockerRegistryEndpoint registry;
49+
private @CheckForNull String toolName;
4450

4551
@DataBoundConstructor public RegistryEndpointStep(@Nonnull DockerRegistryEndpoint registry) {
4652
assert registry != null;
@@ -51,6 +57,14 @@ public DockerRegistryEndpoint getRegistry() {
5157
return registry;
5258
}
5359

60+
public String getToolName() {
61+
return toolName;
62+
}
63+
64+
@DataBoundSetter public void setToolName(String toolName) {
65+
this.toolName = toolName;
66+
}
67+
5468
public static class Execution extends AbstractEndpointStepExecution {
5569

5670
private static final long serialVersionUID = 1;
@@ -60,9 +74,11 @@ public static class Execution extends AbstractEndpointStepExecution {
6074
@StepContextParameter private transient FilePath workspace;
6175
@StepContextParameter private transient Launcher launcher;
6276
@StepContextParameter private transient TaskListener listener;
77+
@StepContextParameter private transient Node node;
78+
@StepContextParameter private transient EnvVars envVars;
6379

6480
@Override protected KeyMaterialFactory newKeyMaterialFactory() throws IOException, InterruptedException {
65-
return step.registry.newKeyMaterialFactory(job, workspace.getChannel(), launcher, listener);
81+
return step.registry.newKeyMaterialFactory(job, workspace, launcher, listener, DockerTool.getExecutable(step.toolName, node, listener, envVars));
6682
}
6783

6884
}

src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Docker implements Serializable {
3737
public <V> V withRegistry(String url, String credentialsId = null, Closure<V> body) {
3838
node {
3939
script.withEnv(["DOCKER_REGISTRY_URL=${url}"]) {
40-
script.withDockerRegistry([url: url, credentialsId: credentialsId]) {
40+
script.withDockerRegistry(registry: [url: url, credentialsId: credentialsId], toolName: script.env.DOCKER_TOOL_NAME) {
4141
body()
4242
}
4343
}

src/main/resources/org/jenkinsci/plugins/docker/workflow/RegistryEndpointStep/config.jelly

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ THE SOFTWARE.
2525
<?jelly escape-by-default='true'?>
2626
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
2727
<f:property field="registry"/>
28+
<d:selectDockerTool field="toolName" xmlns:d="/lib/docker/commons"/>
2829
</j:jelly>

src/test/java/org/jenkinsci/plugins/docker/workflow/WithContainerStepTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import com.cloudbees.plugins.credentials.CredentialsProvider;
2727
import com.cloudbees.plugins.credentials.CredentialsScope;
28+
import com.cloudbees.plugins.credentials.SecretBytes;
2829
import com.cloudbees.plugins.credentials.domains.Domain;
2930
import hudson.model.FileParameterValue;
3031
import hudson.model.Result;
@@ -205,7 +206,7 @@ public class WithContainerStepTest {
205206
File f = tmp.newFile("some-file");
206207
FileUtils.write(f, "some-content");
207208
FileItem fi = new FileParameterValue.FileItemImpl(f);
208-
FileCredentialsImpl fc = new FileCredentialsImpl(CredentialsScope.GLOBAL, "secretfile", "", fi, fi.getName(), null);
209+
FileCredentialsImpl fc = new FileCredentialsImpl(CredentialsScope.GLOBAL, "secretfile", "", fi, fi.getName(), (SecretBytes) null);
209210
CredentialsProvider.lookupStores(story.j.jenkins).iterator().next().addCredentials(Domain.global(), fc);
210211
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "prj");
211212
p.setDefinition(new CpsFlowDefinition(

0 commit comments

Comments
 (0)