Skip to content

[JENKINS-51395] Syntax problems in withDockerRegistry#138

Merged
jglick merged 7 commits intojenkinsci:masterfrom
jglick:withDockerRegistry-syntax-JENKINS-51395
May 17, 2018
Merged

[JENKINS-51395] Syntax problems in withDockerRegistry#138
jglick merged 7 commits intojenkinsci:masterfrom
jglick:withDockerRegistry-syntax-JENKINS-51395

Conversation

@jglick
Copy link
Member

@jglick jglick commented May 17, 2018

JENKINS-51395: #133 broke scripts using the notation

withDockerRegistry([…])

which is unfortunately what Pipeline Syntax suggests if you have no toolName. (@abayer patched both DSL and SnippetizerTest in jenkinsci/workflow-cps-plugin#49, but the behaviors do not seem to actually match in the case that there is one required structure parameter and an optional parameter.)

@oleg-nenashev had written some test coverage for the configuration form of this step long ago, but it did not actually attempt to run the step, and the DSL docker.withRegistry always calls the more verbose form.

It is no longer possible to compatibly remove the new toolName parameter, and anyway we need it, so my current plan is to try to inline the DockerRegistryEndpoint parameter, assuming that is even possible.

Copy link
Member

@jvz jvz left a comment

Choose a reason for hiding this comment

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

🐝

}

@Override public Step newInstance(Map<String, Object> arguments) throws Exception {
if (arguments.containsKey("url") || arguments.containsKey("credentialsId")) {
Copy link
Member

Choose a reason for hiding this comment

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

Direct mutation of input Map: danger, danger will robinson!

Please create copy if you're going to mutate something (just in case something else is done with the args) -- don't remember off the top of my head but there's a real risk this might break something like ArgumentsActionImpl.

Copy link
Member

Choose a reason for hiding this comment

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

It's not a hard-blocker for a known-and-significant error, but it's dangerous to be doing this here.

Copy link
Member Author

Choose a reason for hiding this comment

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

(resolved)

}

@Override public Step newInstance(Map<String, Object> arguments) throws Exception {
if (arguments.containsKey("url") || arguments.containsKey("credentialsId")) {
Copy link
Member

Choose a reason for hiding this comment

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

I think you mean url && credentialsId? Or perhaps you need a handling for one but not the other?

Copy link
Member

Choose a reason for hiding this comment

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

Eh, apparently this is legal. Just weird looking, but legal.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is what I meant. You may have a url and/or a credentialsId.

if (arguments.containsKey("registry")) {
throw new IllegalArgumentException("cannot mix url/credentialsId with registry");
}
arguments.put("registry", new DockerRegistryEndpoint((String) arguments.remove("url"), (String) arguments.remove("credentialsId")));
Copy link
Member

Choose a reason for hiding this comment

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

Will this actually work if you have a credential but not a URL? Or vice versa?

If not, should print something reasonable as an error.

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind, the test covers this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes,

withDockerRegistry(credentialsId: '') {…}

logs you in to Docker Hub rather than a private registry. Conversely, if there were some way to have a non-password-protected private registry (or if it had read-only access and you were not pushing anything), you could

withDockerRegistry(url: '') {…}

Copy link
Member

@svanoort svanoort left a comment

Choose a reason for hiding this comment

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

Looks like it has a few small issues to me but is generally reasonable AFAICT

Copy link
Member

@svanoort svanoort left a comment

Choose a reason for hiding this comment

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

Okay, I think my concerns are addressed after a deeper examination -- the Docker APIs here are... odd.

Copy link
Member

@svanoort svanoort left a comment

Choose a reason for hiding this comment

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

Much happier without the in-place mutation

@jglick jglick merged commit e8a1815 into jenkinsci:master May 17, 2018
@jglick jglick deleted the withDockerRegistry-syntax-JENKINS-51395 branch May 17, 2018 18:25
@jglick jglick mentioned this pull request Nov 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants