Skip to content

Commit 84a7992

Browse files
committed
implemented groovy script to configure admin user creation using environment variables passed to the vm
1 parent fe9d810 commit 84a7992

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

tfgrid3/jenkins/Dockerfile

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@ FROM ubuntu
22

33
RUN apt update
44
RUN apt -y install wget openssh-server
5-
RUN apt -y install gnupg
65

7-
RUN wget -O /usr/share/keyrings/jenkins-keyring.asc \
8-
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
6+
RUN wget -O /usr/share/keyrings/jenkins-keyring.asc https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
7+
RUN echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/" | tee /etc/apt/sources.list.d/jenkins.list > /dev/null
98

10-
RUN echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" \
11-
https://pkg.jenkins.io/debian-stable binary/ | tee \
12-
/etc/apt/sources.list.d/jenkins.list > /dev/null
13-
14-
RUN apt-get update
15-
RUN apt -y install jenkins
9+
RUN apt-get update && apt-get -y install jenkins default-jre
1610

1711
RUN wget -O /sbin/zinit https://github.com/threefoldtech/zinit/releases/download/v0.2.5/zinit && chmod +x /sbin/zinit
12+
1813
COPY rootfs /
1914

20-
EXPOSE 8080
15+
RUN mkdir -p /root/.jenkins/init.groovy.d
16+
COPY /set-admin-user.groovy /root/.jenkins/init.groovy.d/set-admin-user.groovy
17+
18+
EXPOSE 9090
19+
2120
ENTRYPOINT [ "/sbin/zinit", "init" ]

tfgrid3/jenkins/rootfs/etc/zinit/print-jenkins-password.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
exec: /usr/bin/jenkins
1+
exec: /usr/bin/jenkins --httpPort=9090

tfgrid3/jenkins/set-admin-user.groovy

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!groovy
2+
3+
import jenkins.model.*
4+
import hudson.security.*
5+
6+
def instance = Jenkins.getInstance()
7+
8+
def adminUsername = System.getenv("JENKINS_ADMIN_USERNAME") ?: "admin"
9+
def adminPassword = System.getenv("JENKINS_ADMIN_PASSWORD") ?: "admin"
10+
11+
def hudsonRealm = new HudsonPrivateSecurityRealm(false)
12+
hudsonRealm.createAccount(adminUsername, adminPassword)
13+
instance.setSecurityRealm(hudsonRealm)
14+
15+
def strategy = new FullControlOnceLoggedInAuthorizationStrategy()
16+
instance.setAuthorizationStrategy(strategy)
17+
instance.save()

0 commit comments

Comments
 (0)