[stable/jenkins] display error when admin user does not exist. (#16949)

* Display error when admin user does not exist.

Print an error message when `master.sidecars.configAutoReload.enabled` is `true`, but the admin user which is needed to configure the SSH key does not exist.

Signed-off-by: Torsten Walter <mail@torstenwalter.de>

* only configure ssh key if user exists

Signed-off-by: Torsten Walter <mail@torstenwalter.de>
This commit is contained in:
Torsten Walter
2019-09-13 03:16:29 -07:00
committed by Kubernetes Prow Robot
parent ba39474fa0
commit fe27fa7750
3 changed files with 18 additions and 12 deletions
+4
View File
@@ -6,6 +6,10 @@ numbering uses [semantic versioning](http://semver.org).
NOTE: The change log until version 1.5.7 is auto generated based on git commits. Those include a reference to the git commit to be able to get more details.
## 1.6.1
Print error message when `master.sidecars.configAutoReload.enabled` is `true`, but the admin user can't be found to configure the SSH key.
## 1.6.0
Add support for Google Cloud Storage for backup CronJob (migrating from nuvo/kube-tasks to maorfr/kube-tasks)
+1 -1
View File
@@ -1,7 +1,7 @@
apiVersion: v1
name: jenkins
home: https://jenkins.io/
version: 1.6.0
version: 1.6.1
appVersion: lts
description: Open source continuous integration server. It supports multiple SCM tools
including CVS, Subversion and Git. It can execute Apache Ant and Apache Maven-based
+13 -11
View File
@@ -297,18 +297,20 @@ data:
init-add-ssh-key-to-admin.groovy: |-
import jenkins.security.*
import hudson.model.User
import jenkins.security.ApiTokenProperty
import jenkins.model.Jenkins
User u = User.get("{{ .Values.master.adminUser | default "admin" }}")
ApiTokenProperty t = u.getProperty(ApiTokenProperty.class)
String sshKeyString = new File('/var/jenkins_home/key.pub').text
keys_param = new org.jenkinsci.main.modules.cli.auth.ssh.UserPropertyImpl(sshKeyString)
u.addProperty(keys_param)
def inst = Jenkins.getInstance()
def sshDesc = inst.getDescriptor("org.jenkinsci.main.modules.sshd.SSHD")
sshDesc.setPort({{ .Values.master.sidecars.configAutoReload.sshTcpPort | default 1044 }})
sshDesc.getActualPort()
sshDesc.save()
User user = User.get("{{ .Values.master.adminUser | default "admin" }}", false)
if (user == null) {
System.err.println("ERROR: user '{{ .Values.master.adminUser | default "admin" }}' not found! Can't configure SSH key which is needed to reload JCasC config!")
} else {
String sshKeyString = new File('/var/jenkins_home/key.pub').text
keys_param = new org.jenkinsci.main.modules.cli.auth.ssh.UserPropertyImpl(sshKeyString)
user.addProperty(keys_param)
def inst = Jenkins.getInstance()
def sshDesc = inst.getDescriptor("org.jenkinsci.main.modules.sshd.SSHD")
sshDesc.setPort({{ .Values.master.sidecars.configAutoReload.sshTcpPort | default 1044 }})
sshDesc.getActualPort()
sshDesc.save()
}
{{- else }}
# Only add config to this script if we aren't auto-reloading otherwise the pod will restart upon each config change:
{{- range $key, $val := .Values.master.JCasC.configScripts }}