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:

  • Using variable interpolation in string in Docker
  • How to map the IP address of docker container to another container dynamically
  • Unable to run shell script using dockerfile
  • Installing chef-server in a docker container
  • How to get into psql of a running postgres container?
  • alpine linux — autossh (missing)
  • # 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: Error starting container: Unable to load the AUFS module
  • How to avoid reinstalling packages when building Docker image for Python projects?
  • Docker History Base Image Add:sha256hash
  • Docker container exits immediately despite Service Running
  • How to properly deploy Docker containers with supervisord to Jelastic
  • Kubernetes on Mesos, no suitable offer available
  • 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=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.

    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.