openshift / jenkins

Apache License 2.0
260 stars 447 forks source link

create_jenkins_location_configuration_xml in s2i running everytime and removing email address #1705

Closed jonespm closed 6 months ago

jonespm commented 1 year ago

We're running Jenkins using s2i on Openshift and every restart the email address was getting removed and replaced with

"address not configured yet nobody@nowhere"

I tracked it down to this function running here https://github.com/openshift/jenkins/blob/57d4ffbf08c29bd2e74fb4a5bec5240b62c1f313/2/contrib/s2i/run#L573

and it's executed immediately afterward every restart at https://github.com/openshift/jenkins/blob/57d4ffbf08c29bd2e74fb4a5bec5240b62c1f313/2/contrib/s2i/run#L587

The value it's replacing is with the one in jenkins.model.JenkinsLocationConfiguration.xml.tpl in https://github.com/openshift/jenkins/tree/master/2/contrib/openshift/configuration

Am I missing a step in the setup? The only thing I can think of to work around this without fixing this file are:

Is there something I'm missing. I don't think this function needs to even run every time. It could check if ${JENKINS_HOME}/configured is set and avoid doing it again like other functions do.

Thanks!

coreydaley commented 1 year ago

I wonder if it would make sense to make it an env var instead that gets replaced into the template the same way?

jonespm commented 1 year ago

The current env var of JENKINS_URL is also set by this code and can't be overridden by the environment. I think it could also be a solution if the script would check if both of those were already set or not in the environment and use what's there like it does with JENKINS_JAVA_OPTIONS, JENKINS_SERVICE_NAMEand some others. Then I could pass JENKINS_ADMIN_ADDRESS and be good to go too.

coreydaley commented 1 year ago

If you would like to put together a proposal/pull request I would be happy to review it.

jonespm commented 11 months ago

I haven't had a chance to try to fix this here yet. I've just been working around this with this groovy script running after Jenkins starts. I just set the JENKINS_ADMIN_EMAIL and have this file on the persistent volume in /var/lib/jenkins/init.groovy.d

// This groovy script works around the bug on https://github.com/openshift/jenkins/issues/1705 and sets the email to match JENKINS_ADMIN_EMAIL
// Just place this in /var/lib/jenkins/init.groovy.d/update-email-address.groovy

import jenkins.model.Jenkins
import jenkins.model.JenkinsLocationConfiguration

// Check if the email address is set in the environment
def adminEmail = System.getenv("JENKINS_ADMIN_EMAIL")

// If the environment variable is not set, use a default value
if (adminEmail == null || adminEmail.isEmpty()) {
    adminEmail = "admin@jenkins.com" // Default email address
}

// get Jenkins location configuration
def jenkinsLocationConfiguration = JenkinsLocationConfiguration.get()

// set Jenkins admin email address
jenkinsLocationConfiguration.setAdminAddress(adminEmail)

// save current Jenkins state to disk
jenkinsLocationConfiguration.save()
openshift-bot commented 8 months ago

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close. Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

openshift-bot commented 7 months ago

Stale issues rot after 30d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle rotten. Rotten issues close after an additional 30d of inactivity. Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle rotten /remove-lifecycle stale

openshift-bot commented 6 months ago

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen. Mark the issue as fresh by commenting /remove-lifecycle rotten. Exclude this issue from closing again by commenting /lifecycle frozen.

/close

openshift-ci[bot] commented 6 months ago

@openshift-bot: Closing this issue.

In response to [this](https://github.com/openshift/jenkins/issues/1705#issuecomment-1955423911): >Rotten issues close after 30d of inactivity. > >Reopen the issue by commenting `/reopen`. >Mark the issue as fresh by commenting `/remove-lifecycle rotten`. >Exclude this issue from closing again by commenting `/lifecycle frozen`. > >/close Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.