5

I'm trying to create my own Jenkins image that skips the wizard and sets the admin password via an environment variable.

I tried setting the state to disable it (taken from the Mesosphere Jenkins service) but that didn't work:

# disable first-run wizard
RUN echo 2.0 > ${JENKINS_STAGING}/jenkins.install.UpgradeWizard.state

How can I skip the wizard and set the admin password via a variable instead of the password being auto-generated?

Ken J
  • 4,312
  • 12
  • 50
  • 86

2 Answers2

10

If you are using the jenkins/jenkins image from Docker Hub ( https://hub.docker.com/r/jenkins/jenkins/ ), then you can disable the setup wizard by setting this environment variable:

JAVA_OPTS=-Djenkins.install.runSetupWizard=false

And to pre-configure the admin user, you can do that with this environment varible:

JENKINS_OPTS=--argumentsRealm.roles.user=admin --argumentsRealm.passwd.admin=admin --argumentsRealm.roles.admin=admin

Here's a docker-compose example which I've been using locally:

version: '3'

services:
  jenkins:
    image: jenkins/jenkins:2.150.3-alpine
    environment:
      JAVA_OPTS: -Djenkins.install.runSetupWizard=false
      JENKINS_OPTS: --argumentsRealm.roles.user=admin --argumentsRealm.passwd.admin=admin --argumentsRealm.roles.admin=admin
    volumes:
      - ./jenkins_home:/var/jenkins_home
    ports:
      - 8080:8080
Zahiar
  • 244
  • 1
  • 5
  • 9
7

The correct way to set the admin password is to start Jenkins with parameters:

java ${JVM_OPTS}                                \
 -Dhudson.udp=-1                                 \
 -Djava.awt.headless=true                        \
 -Dhudson.DNSMultiCast.disabled=true             \
 -Djenkins.install.runSetupWizard=false          \
 -jar ${JENKINS_FOLDER}/jenkins.war              \
 ${JENKINS_OPTS}                                 \
 --httpPort=${PORT1}                             \
 --webroot=${JENKINS_FOLDER}/war                 \
 --ajp13Port=-1                                  \
 --httpListenAddress=0.0.0.0                  \
 --ajp13ListenAddress=0.0.0.0                 \
 --argumentsRealm.passwd.admin=${PASSWORD}       \
 --argumentsRealm.roles.user=admin               \
 --argumentsRealm.roles.admin=admin               \
 --prefix=${JENKINS_CONTEXT}

In this case the --argumentsRealm* parameters are the most important as they set the role and the password for admin.

user3063045
  • 2,019
  • 2
  • 22
  • 35