Race condition can prevent setup wizard from initializing properly

Details

Description

The setup wizard initialization currently happens once the InitMilestone.COMPLETED is reached.

On the first Jenkins startup, there is a risk that some code executed in another thread would call Jenkins#save before the setup wizard is initialized. Such code could be a groovy script, or in a third-party plugin.

In such a case, the Setup Wizard would be initialized with state RESTART and the instance wouldn't be initialized as expected.

SCM/JIRA link daemon
added a comment - 2018-03-26 07:38 Code changed in jenkins
User: Vincent Latombe
Path:
core/src/main/java/jenkins/model/Jenkins.java
http://jenkins-ci.org/commit/jenkins/9f599911f6125cd69dc45718a4bbf79644be74e8
Log:
JENKINS-49401 Move Setup Wizard initialization logic to the init reactor. (#3282)
This way, it is guaranteed Jenkins.save() has never been called before
the SetupWizard is executed, and computation of the initial Setup Wizard
state will be correct.
Since the SetupWizard is now executed before reaching the COMPLETED
milestone, a Jenkins.save() call has been added in order to persist any
configuration change done in prior phases.

SCM/JIRA link daemon
added a comment - 2018-04-24 12:47 Code changed in jenkins
User: Vincent Latombe
Path:
core/src/main/java/jenkins/model/Jenkins.java
http://jenkins-ci.org/commit/jenkins/f5a2401c8a38b4c51e5dc5a7542326aa25343143
Log:
JENKINS-49401 Move Setup Wizard initialization logic to the init reactor. (#3282)
This way, it is guaranteed Jenkins.save() has never been called before
the SetupWizard is executed, and computation of the initial Setup Wizard
state will be correct.
Since the SetupWizard is now executed before reaching the COMPLETED
milestone, a Jenkins.save() call has been added in order to persist any
configuration change done in prior phases.
(cherry picked from commit 9f599911f6125cd69dc45718a4bbf79644be74e8)

yan-hong wang
added a comment - 2018-05-16 07:44 Hello all,
Since I upgrade from jenkins/jenkins:2.107.2-alpine to jenkins/jenkins:2.107.3-alpine , I met the error message in Jenkins log.
$ kubectl logs jenkins-75854794bd-xwpjv --follow
....
....
....
May 16, 2018 9:29:28 AM jenkins.install.SetupWizard init
INFO:
*************************************************************
*************************************************************
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
40c3824c3c6e45739d616b18af590c19
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
May 16, 2018 9:29:32 AM hudson.model.UpdateCenter updateDefaultSite
WARNING: Upgrading Jenkins. Failed to update the default Update Site 'default'. Plugin upgrades may fail.
java.net.UnknownHostException: updates.jenkins.io
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
...
...
...
So is there any some way to skip SetupWizard?
I tried to add ' RUN echo 2.0 > /usr/share/jenkins/ref/jenkins.install.UpgradeWizard.state ' into Dockerfile .
Or append ' instance.setInstallState( InstallState.INITIAL_SETUP_COMPLETED ) ' to my customized groovy file.
It still didn't work......
Now I could only still keep Jenkins in 2.107.2-alpine version.
Thanks very much.
Hong