docker icon indicating copy to clipboard operation
docker copied to clipboard

environment variable substitution for config files in /usr/share/jenkins/ref/

Open jpraet opened this issue 7 years ago • 3 comments

It would be nice if environment variables (or another placeholder replacement mechanism) could be used for the config files in /usr/share/jenkins/ref/. For example:

hudson.tasks.Mailer.xml:

<?xml version='1.0' encoding='UTF-8'?>
<hudson.tasks.Mailer_-DescriptorImpl plugin="[email protected]">
  <hudsonUrl>http://jenkins.example.com/</hudsonUrl>
  <smtpHost>smtp.example.com</smtpHost>
  <useSsl>false</useSsl>
  <charset>UTF-8</charset>
</hudson.tasks.Mailer_-DescriptorImpl>

jenkins.model.JenkinsLocationConfiguration.xml:

<?xml version='1.0' encoding='UTF-8'?>
<jenkins.model.JenkinsLocationConfiguration>
  <adminAddress>[email protected]</adminAddress>
  <jenkinsUrl>http://jenkins.example.com/</jenkinsUrl>
</jenkins.model.JenkinsLocationConfiguration>

I would like to provide these default configuration files in /usr/share/jenkins/ref/, but the http://jenkins.example.com/ should be specified dynamically when running the container (e.g. for another instance in a test environment).

So I'd like to be able to write something like <jenkinsUrl>${JENKINS_URL}</jenkinsUrl> or maybe with a default value <jenkinsUrl>${JENKINS_URL-http://jenkins.example.com/}</jenkinsUrl>

and then specify a value at runtime with docker run -e "JENKINS_URL=http://jenkins-test.example.com/"

What do you think?

jpraet avatar Mar 10 '17 19:03 jpraet

Alternatively you can using groovy.init.d to configure Jenkins. From here you are able to access environment variables using System.getenv("VARIABLE_NAME"), in your case: System.getenv("JENKINS_URL")

hoshsadiq avatar Mar 22 '17 18:03 hoshsadiq

I have similar requirement, basically I want jenkins container configuration to be different for different Kuberentes project . example: jenkins/sonarqube for one Kuberentes namespace will be having different names vs second namespace (jenkins/sonarqube). However I want to build standard image where based on environment variable I can update hudson.plugins.sonar.SonarGlobalConfiguration.xml for <serverUrl>$SONAR_URL</serverUrl> and <serverAuthenticationToken>$TOKEN</serverAuthenticationToken>

if this can be achieved by groovy option, could you explain little more on how to use goovy.init.d

Regards Priyanka

PriyankaSuchak avatar Aug 17 '18 00:08 PriyankaSuchak

I think this is not specific to the container but a more generally useful suggestion. Some people asked for a similar thing here: https://issues.jenkins-ci.org/browse/JENKINS-28466?focusedCommentId=283101&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-283101

ibaldonl avatar Jun 05 '19 20:06 ibaldonl