Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Docker Set Admin Password from Environment Variable

Tags:

docker

jenkins

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?

like image 880
Ken J Avatar asked Dec 05 '22 14:12

Ken J


2 Answers

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
like image 56
Zahiar Avatar answered Mar 16 '23 23:03

Zahiar


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.

like image 41
user3063045 Avatar answered Mar 16 '23 23:03

user3063045