15

I already searched the related questions like here;

How do I get initial admin password for jenkins on Mac?

and here;

How to recover Jenkins password

However, I cannot find a solution for my problem.

I am following the instructions to install jenkins on this link;

https://jenkins.io/doc/book/installing/

and I have run the following commands to install and tried to make it run on my local machine (mac os);

docker run \
  -u root \
  --rm \
  -d \
  -p 8080:8080 \
  -p 50000:50000 \
  -v jenkins-data:/var/jenkins_home \
  -v /var/run/docker.sock:/var/run/docker.sock \
  jenkinsci/blueocean

It installs it properly but when I get to the login screen it asks for the initial admin password. Because the installation runs in (-d mode) backend, I cannot see the initial password after the installation completes. When I remove -d for the installation, then the installation does not work.

I also checked the shared folder (User/Shared/Jenkins/Home) directory and there was no secrets folder in it. So I created one manually and followed the instructions (in the answers) on this link again;

How do I get initial admin password for jenkins on Mac?

Afterwards, I removed the related docker process and restarted all the installation process from the beginning but I got the same result.

In this case, how can I find this initial admin password or how can I generate it again?

BTW: I am also checking the logs (where in /var/log/jenkins) but it seems that it stopped writing there after my first install attempt and I also couldn't find the initial password there).

7 Answers7

57

docker exec <container_name> cat /var/jenkins_home/secrets/initialAdminPassword

Rodrigo Queiroz
  • 2,674
  • 24
  • 30
30

I tried looking into the container's filesystem, but there's no secrets folder in it. But I found the solution in the jenkins documentation here

Docker outputs the initial secret to the console

To view the console use the command

docker logs <container id of jenkins>

output is somemthing like this: enter image description here

Sudip Bhattarai
  • 1,082
  • 9
  • 23
7

If you are using Mac and Docker installation for Jenkins follow bellow steps to get initial administer password to start authentication in Jenkins Console. Type below command in Terminal.

(Note: This is working, if you have follow default steps in Jenkins documentation to install Jenkins in Docker environment)

Find the running containers

: docker ps

Copy the running containerID

: docker exec -it <containerID> bash

: cd /var/jenkins_home/secrets

: cat initialAdminPassword

Use secret password showing in terminal and used as initial password for Jenkins Console.

Dimuthu
  • 1,611
  • 1
  • 14
  • 16
3

If you have installed Jenkins via docker, then the following command can give you the initial admin password. Assuming your container name/docker image name is jenkins

docker exec `docker ps | grep jenkins | awk '{ print $1}' ` cat /var/jenkins_home/secrets/initialAdminPassword
akshaykrjain
  • 373
  • 2
  • 8
2

docker exec $(docker ps -q) cat /var/jenkins_home/secrets/initialAdminPassword

raju
  • 53
  • 6
1

For me username was: admin and you can find password by:

docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword

my container name is jenkins

Darwin
  • 1,695
  • 1
  • 19
  • 29
0

Can you install docker-compose and docker toolbox on your Mac? https://docs.docker.com/compose/install/ Try to execute this docker-compose.yml file:

version: '3.1'
services:

  blue-ocean:
    image: jenkinsci/blueocean:latest
    container_name: blue-ocean
    restart: always
    environment:
      TZ: America/Mexico_City
    ports:
      - 8080:8080
      - 50000:50000
    tty: true
    volumes:
      - ./jenkins-data:/var/jenkins_home
      - ./sock:/var/run/docker.sock

Only you need to create a folder with a docker-compose.yml file inside and execute the docker-compose up -d command in terminal, then the folders jenkins-data and sock will be created and inside of jenkins-data appear the directory ./jenkins-data/secrets/initialAdminPassword, open this file and copy the content and paste on the input of web view that requires it.

Brayan Caldera
  • 2,001
  • 2
  • 11
  • 20
  • Hi, I don't have 'secrets' folder in 'jenkins-data' folder. So, I cannot find the initialAdminPassword file. Why does that happen? –  Jun 24 '18 at 15:19
  • 1
    After awhile, the 'secrets' folder was created. Now, I found it and could pass the password page :) Thank you very much! –  Jun 24 '18 at 15:23
  • I believe this answer is not good. Why? Although it works, it is not answering with an actionable solution for the problem so it shouldn't be taken as acceptable answer. Also @user2147431 should be made aware that the folder ".../secrets/..." is not on the host OS (macOS, Linux, whatever... is the same on every Docker deployment) but on the guest/container's once it's bootstrapped. – Hugo Tavares Jul 25 '19 at 15:49