Closed ntwrkguru closed 2 years ago
This works, so looks like something with the template
is not parsing properly.
enkins:
clouds:
- docker:
dockerApi:
connectTimeout: 60
dockerHost:
uri: "unix:///var/run/docker.sock"
readTimeout: 60
name: "docker"
Hmm, I think you're reporting multiple, but different, issues here.
First, the issue with the groovy script; yes, you're right, it's out of date. There's an existing PR (#799) to fix that, although that's been stalled awaiting further fixes. If you know enough about groovy to help on that, please do contribute.
Re: the JCasC exception
java.lang.NullPointerException
at com.nirima.jenkins.plugins.docker.DockerTemplate.hashCode(DockerTemplate.java:708)
does suggest you're right...
It looks like DockerTemplate.java:708 assumes that connector
will not be null.
...but that's been like that for years so this issue can't've been caused recently by that code...
...so if we go back further, we see that DockerTemplate.hashCode()
is being called from DockerCloud.java:718 but that's also been like that for years too, so that can't be responsible for recent breakages either.
So, overall, it looks like JCasC is calling hashCode
on objects that aren't properly populated.
...so that suggests that the problem there is that the objects aren't being populated - connector
must not be null for hashCode
to work, but it is null.
...so perhaps the error is in the specification of the connector:
section of the JCasC yaml.
I know very little about JCasC so I can't be much help debugging that, other than to say that the template's connector field will probably need to create a DockerComputerAttachConnector ... and that I don't see anything wrong with the yaml specified there.
...however, your later exception trace stemming from NodeProvisioner
shows that, at some point during your experimentation, you managed to push an invalid (connector==null) docker template configuration into your Jenkins cloud configuration, and that would've then prevented anything else from getting very far thereafter.
So it may be that, once you'd hit one error, all subsequent attempts to diagnose issues fell foul of the unclean fallout from the first; there may not be anything wrong with the JCasC stuff - it might work in a clean environment.
Thanks for the feedback. My main point was to raise that the examples are not working. As far as clean environment, it is absolutely clean; declaratively instantiated at will. I don't know groovy very well, and know even less about Java, so I can't help much to resolve these issues. If I omit the image template, it does work (and I don't need the template, so it works out).
@ntwrkguru just checked the yaml example and it works like expected. I tested it inside official docker container:
Could it be the case that YAML was been broken during copy-paste with some hidden characters?
@pjdarton regarding the outdated groovy script example, I've created a PR #1 to the forked version so once the author accepts it, #799 should be unblocked for further reviewing.
Could it be the case that YAML was been broken during copy-paste with some hidden characters?
@maxim-nazarenko Could be, sure. Although it seemed very specific to the slave image declaration and I copied from raw to vim, which usually is ok.
I've now merged #799 and added some improvements myself (well, I think they're improvements 😉) i.e. we should now have a workable groovy script in the latest code.
I'm not sure about the JCasC issues - it could be that things would behave a little better if we null-proofed hashCode & equals ... but without proof that that's necessary I'm reluctant to do that as it ought to be unnnecessary and it'll impede efficiency in the general case. i.e. unless such changes are shown to be of benefit, I'll continue to treat them as unnecessary (and claim "it's not my fault" 😉)
There were JCasC issues, but I know (as I'm using JCasC myself now) that this now works OK. There's a few rough edges (and PRs to resolve those) but it's basically "there" so I'm going to close this as "fixed".
Pre-configuring a cloud with this plugin produces an error, both when using the provided groovy script and when using the example yaml snippet for the Jenkins Configuration as Code plugin. Manual configuration of the plugin in the environment works fine. I've even tried manually configuring the cloud with the plugin, then copying the relevant section for
cloud:
from the generatedjenkins.yaml
file, and feeding it back in during deployment...the same error for the configuration as code plugin, exists.Error from the groovy script approach:
Output from Configuration as Code approach: