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:

  • Add new Tomcat containers behind Apache with Docker
  • ASP.NET 5.0 beta 8 in Docker doesn't start
  • How to organize containers “horizontally” inside Kubernetes pods?
  • Can I ask for RAM of container exceed the physical memory on the single host with Docker-Swarm
  • What is happening in my Docker when deploying with rocketeer?
  • Gitlab Continuous Integration on Docker
  • # 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?

  • dockerized HAProxy+Keepalived for HA
  • Install + start ssh in dockerfile derived from official jenkins docker image
  • How to access screen shots made in CI test on specific gitlab-runner
  • No docker-quickstart found on mac
  • Docker container name not resolved as DNS for overlay network not reachable
  • Is it possible to integrate SonarQube, Jenkins and GitLab (all in dockers)?
  • 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.