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:

  • Ambiguous port publish parameters to “docker run”
  • no space left on device while installing a tar using docker
  • Docker tomcat not accessible from browser
  • Is it possible to super scale a dockerised selenium grid?
  • Use custom Visual Studio run configuration with Docker
  • How can I build a coturn server with dockerfile configuration?
  • # 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 compose, link file outside container
  • If docker uses the underlying linux os, why specify the OS in the FROM line of a Dockerfile
  • Running an iPython notebook server on an EC2 Ubuntu instance via Docker
  • Using dockers remote api in docker swarm
  • What does the command gcloud docker -a do?
  • Give multiple tags to docker image using one docker tag command
  • 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.