configuration-as-code-plugin icon indicating copy to clipboard operation
configuration-as-code-plugin copied to clipboard

Add support of dynamically-modifyable system properties in YAML

Open oleg-nenashev opened this issue 7 years ago • 8 comments

Jenkins core has an engine for defining system properties on the flight (SystemProperties in the code or just non-final static fields). It would be great to support such engine in the Condifugation-as-Code plugin

The implementation is TBD

oleg-nenashev avatar Feb 05 '18 16:02 oleg-nenashev

Can you please provide a link to this mechanism ? Never heard about his

ndeloof avatar Aug 09 '18 20:08 ndeloof

I think what @oleg-nenashev meant is to control system properties that Jenkins reads.

So instead of this in a docker image

ENV JAVA_OPTS="-Dhudson.model.DirectoryBrowserSupport.CSP=\"sandbox allow-same-origin allow-scripts; default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src blob: 'self';\" ${JAVA_OPTS}"

It could be something like this:

systemProperties:
  - hudson.model.DirectoryBrowserSupport.CSP: "sandbox allow-same-origin allow-scripts; default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src blob: 'self';"

I'd really love if we got around to this issue 😆

jetersen avatar Aug 29 '19 04:08 jetersen

I'd really like to see that feature implemented too.

To clarify, there is an official list of Jenkins features controlled by system properties here.

Some values like hudson.TcpSlaveAgentListener.hostName are required for configuring a server/agent setup but cannot be set any other way than with a init.grovy.d script as far as I can tell, e.g.,

# ref/init.groovy.d/properties.groovy

host = "jenkins-master"
port = "50000"

System.setProperty("hudson.TcpSlaveAgentListener.hostName", host)
System.setProperty("hudson.TcpSlaveAgentListener.port", port)

jenkins.model.Jenkins.getInstance().save()

Another striking example is the server timezone, which requires something like

time_zone = "Europe/London"

System.setProperty("org.apache.commons.jelly.tags.fmt.timeZone", time_zone)

It would be very nice to have these values handled by CasC, this would help getting rid of the init.groovy.d scripts for good.

chroche avatar Oct 18 '19 09:10 chroche

The problem with #1204 is you would have another chicken and egg problem (at least with the current implementation) 😭

jetersen avatar Nov 25 '19 18:11 jetersen

as mentioned in #1204 system properties need to be set much earlier than configuration as Jenkins and/or plugins can change behaviour based on them and they are not expected to change post initialisation.

jtnord avatar Nov 25 '19 19:11 jtnord

The problem with #1204 is you would have another chicken and egg problem (at least with the current implementation) 😭

I assume you would run it as the very first configurator, possibly even in an earlier initialiser?

timja avatar Nov 25 '19 20:11 timja

We could add support for it directly in the Jenkins core 🤷‍♂ . Even with YAML input, why not

oleg-nenashev avatar Jan 02 '20 17:01 oleg-nenashev

are there any updates?

giovinazzorocco avatar Oct 18 '22 15:10 giovinazzorocco