Skip to content

Commit

Permalink
[FIXED JENKINS-39684] Add registryUrl and registryCredentialsId
Browse files Browse the repository at this point in the history
Added to both docker and dockerfile agent types. Not sure how to test
this, honestly.
  • Loading branch information
abayer committed Jan 10, 2017
1 parent 953af55 commit d76175b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
Expand Up @@ -38,12 +38,33 @@ public class DockerPipeline extends DeclarativeAgent<DockerPipeline> {
private String label;
private String image;
private String args = "";
private String registryUrl;
private String registryCredentialsId;

@DataBoundConstructor
public DockerPipeline(@Nonnull String image) {
this.image = image;
}

public @Nullable String getRegistryUrl() {
return registryUrl;
}

@DataBoundSetter
public void setRegistryUrl(String registryUrl) {
this.registryUrl = registryUrl;
}

public @Nullable String getRegistryCredentialsId() {
return registryCredentialsId;
}

@DataBoundSetter
public void setRegistryCredentialsId(String registryCredentialsId) {
this.registryCredentialsId = registryCredentialsId;
}


public @Nullable String getLabel() {
return label;
}
Expand Down
Expand Up @@ -33,16 +33,37 @@

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class DockerPipelineFromDockerfile extends DeclarativeAgent<DockerPipelineFromDockerfile> {
private String label;
private String filename;
private String args = "";
private String registryUrl;
private String registryCredentialsId;

@DataBoundConstructor
public DockerPipelineFromDockerfile() {
}

public @Nullable String getRegistryUrl() {
return registryUrl;
}

@DataBoundSetter
public void setRegistryUrl(String registryUrl) {
this.registryUrl = registryUrl;
}

public @Nullable String getRegistryCredentialsId() {
return registryCredentialsId;
}

@DataBoundSetter
public void setRegistryCredentialsId(String registryCredentialsId) {
this.registryCredentialsId = registryCredentialsId;
}

public @CheckForNull String getLabel() {
return label;
}
Expand Down
Expand Up @@ -45,6 +45,18 @@ public class DockerPipelineFromDockerfileScript extends DeclarativeAgentScript<D
}
LabelScript labelScript = (LabelScript) Label.DescriptorImpl.instanceForName("label", [label: targetLabel]).getScript(script)
return labelScript.run {
if (describable.registryUrl != null) {
script.getProperty("docker").withRegistry(describable.registryUrl, describable.registryCredentialsId) {
runImage(body).call()
}
} else {
runImage(body).call()
}
}
}

public Closure runImage(Closure body) {
return {
def img = null
if (!Utils.withinAStage()) {
script.stage(SyntheticStageNames.agentSetup()) {
Expand Down Expand Up @@ -75,7 +87,6 @@ public class DockerPipelineFromDockerfileScript extends DeclarativeAgentScript<D
throw e
}
}

}
}

Expand Down
Expand Up @@ -46,6 +46,18 @@ public class DockerPipelineScript extends DeclarativeAgentScript<DockerPipeline>
}
LabelScript labelScript = (LabelScript) Label.DescriptorImpl.instanceForName("label", [label: targetLabel]).getScript(script)
return labelScript.run {
if (describable.registryUrl != null) {
script.getProperty("docker").withRegistry(describable.registryUrl, describable.registryCredentialsId) {
runImage(body).call()
}
} else {
runImage(body).call()
}
}
}

public Closure runImage(Closure body) {
return {
if (!Utils.withinAStage()) {
script.stage(SyntheticStageNames.agentSetup()) {
Utils.markSyntheticStage(SyntheticStageNames.agentSetup(), Utils.getSyntheticStageMetadata().pre)
Expand Down

1 comment on commit d76175b

@ap0phi5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the benefit of anyone stumbling across this without understanding what has actually changed, example here:

agent {
   docker {
       label ‘docker’
       image ‘myregistry.com/node:7.10.0’
       registryUrl ‘https://myregistry.com/'
       registryCredentialsId ‘myPredefinedCredentialsInJenkins’
   }
 }

Please sign in to comment.