helm-charts
helm-charts copied to clipboard
Change to initScripts does not trigger Jenkins to reinitialize
Describe the bug
When using initScripts, which turns into file changes in init.groovy.d
usually, Jenkins is not instructed to reload its configuration, so the changes in init.groovy.d
do not get processed until unrelated activity triggers the reload.
Version of Helm and Kubernetes
- Helm: version.BuildInfo{Version:"v3.8.1", GitCommit:"5cb9af4b1b271d11d7a97a71df3ac337dd94ad37", GitTreeState:"clean", GoVersion:"go1.17.5"}
- Kubernetes:
Client Version: v1.24.3
Kustomize Version: v4.5.4
Server Version: v1.22.10-gke.600
Chart version
jenkins-4.1.14
What happened?
- Have a setting created in initScripts, such as this:
controller:
initScripts:
setup-known-hosts: |
new File("/var/jenkins_home/.ssh").mkdir()
File file = new File("/var/jenkins_home/.ssh/known_hosts")
file.write '${known_hosts}'
Supply ${known_host}
with a sample from a /home/user/.ssh/known_hosts
file.
- Deploy Jenkins with Helm, and shell into the Jenkins pod and witness the
~/.ssh/known_hosts
file was created. - Update
${known_hosts}
in values.yaml with another host - Deploy Jenkins with Helm again, and shell in again, and witness the
~/.ssh/known_hosts
file was not updated. - Restart the Jenkins pod
- Shell in again and witness the
~/.ssh/known_hosts
file was finally updated.
What you expected to happen?
Jenkins reinitializes and picks up the change at initialization (possibly with a values.yaml
option that must be enabled to grant the reload).
How to reproduce it
See above
Anything else we need to know?
No response
This does not sound unexpected. The behaviour is documented in https://www.jenkins.io/doc/book/managing/groovy-hook-scripts/
You can create a Groovy script file
$JENKINS_HOME/init.groovy
, or any.groovy
file in the directory$JENKINS_HOME/init.groovy.d/
, to run some additional things right after Jenkins starts up. The groovy scripts are executed at the end of Jenkins initialization. This script can access classes in Jenkins and all the plugins. So for example, you can write something like:
So this scripts are only executed after start/re-start.
Sounds like the request is to add a checksum or whatever and restart Jenkins if they change
What one could to is to add an annotation to the pod which contains the checksum of the init scripts similar to what we do here: https://github.com/jenkinsci/helm-charts/blob/main/charts/jenkins/templates/jenkins-controller-statefulset.yaml#L47 Even better would be to include it in that checksum calculation.
@jimsnab do you want to give that a try?
The suggestion looks good. However, I have not developed a Helm chart before. If I can find the time I will try.