Jenkins Docker Set Admin Password from Environment Variable

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:

  • How to change Docker default subnet size?
  • Installing sensu, sensu-dashboard does not install
  • How to persist 'ln' in Docker with Ubuntu
  • Deploy docker image as standalone executable
  • How to mount host directory in docker container?
  • docker push error for ibm bluemix watson
  • # 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?

  • Docker - How to disable PHP ext / modules
  • Can I run DCE (Docker Container Executor) on Yarn with Kerberos?
  • on Docker
  • Docker-Compose won't volume my php.ini file
  • How to give my desktop Ubuntu machine's user full permissions to a docker volume, in addition to TWO users within the docker container?
  • Deploying Docker image to Kubernetes
  • 2 Solutions collect form web for “Jenkins Docker Set Admin Password from Environment Variable”

    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=                  \
     --ajp13ListenAddress=                 \
     --argumentsRealm.passwd.admin=${PASSWORD}       \
     --argumentsRealm.roles.user=admin               \
     --argumentsRealm.roles.admin=admin               \

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

    i’m not sure how to do that. here’s what we do. if you have a shell script that ultimately fires up a jenkins docker container, this command, executed from the host, will allow you to grab the key, in case you want to use it for your nefarious purposes (like logging in):

    admin_key=$(docker exec -t jenkins-ci cat /var/jenkins_home/secrets/initialAdminPassword | sed 's/\r//')

    jenkins-ci is the container name in this case.

    you might also be able to modify that file (docker cp a file in from the host to that location or something). i haven’t tried this to know if it actually works.

    there are other options at this question. good luck with your hot automation!

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.