How to "Unlock Jenkins"?

Viewed 91216

I am installing Jenkins 2 on windows,after installing,a page is opened,URL is:
http://localhost:8080/login?from=%2F

content of the page is like this:
enter image description here

Question:
How to "Unlock Jenkins"?

PS:I have looked for the answer in documentation and google.

31 Answers
  1. Open your terminal and type code below to find all the containers.

    docker container list -a

  2. You will find jenkinsci/blueocean and/or docker:dind if not than

    docker container run --name jenkins-docker --rm --detach ^ --privileged --network jenkins --network-alias docker ^ --env DOCKER_TLS_CERTDIR=/certs ^ --volume jenkins-docker-certs:/certs/client ^ --volume jenkins-data:/var/jenkins_home ^ --volume "%HOMEDRIVE%%HOMEPATH%":/home ^ docker:dind

             and
    

    docker container run --name jenkins-blueocean --rm --detach ^ --network jenkins --env DOCKER_HOST=tcp://docker:2376 ^ --env DOCKER_CERT_PATH=/certs/client --env DOCKER_TLS_VERIFY=1 ^ --volume jenkins-data:/var/jenkins_home ^ --volume jenkins-docker-certs:/certs/client:ro ^ --volume "%HOMEDRIVE%%HOMEPATH%":/home ^ --publish 8080:8080 --publish 50000:50000 jenkinsci/blueocean

  3. run command

    docker run jenkinsci/blueocean or docker run docker:dind

  4. Copy and Paste the secret key.

I have seen a lot of response to the question, most of them were actually solution to it but they solve the problem when jenkins is actually run as a standalone CI without Application container using the command:

java -jar jenkins.war

But when running on Tomcat as it is the case in this scenario, Jenkins logs are displayed on the catalina logs since the software is running on a container. So you need to go to the logs folder:

C:\Program Files\tomcat_folder\Tomcat 8.5\logs\catalina.log 

in my own case. Just scroll almost to the middle to look for a generated password which is essentially a token and copy and paste it to unlock jenkins.

I hope this fix your problem.

Step 1: Open the terminal on your mac

Step 2: Concatenate or Paste

sudo cat **/Users/Shared/Jenkins/Home/secrets/initialAdminPassword**

Step 3: It will ask for password, type your mac password and enter

Step 4: A key would be generated.

Step 5: Copy and paste the security token in Jenkins

Step 6: Click continue

If unable to find Jenkins password in the location C:\Windows\System32\config\systemprofile\.jenkins\secrets\initialAdminPassword

by installing Jenkins generic war on Tomcat server, try below

Solution: Set environmental variable JENKINS_HOME to your jenkins path say

JENKINS_HOME ="C:/users/username/apachetomcat/webapps/jenkins"

Place Jenkins.war in the webapp folder of Tomcat and start Tomcat, initial admin password gets generated in the path

C:\Program Files (x86)\Apache Software Foundation\Tomcat 9.0\webapps\jenkins\secrets\initialAdminPassword

Yet another way to bypass the unlock screen is to copy the UpgradeWizard state to the InstallUtil last execution version, add an install.runSetupWizard file with the contents 'false', and update the config.xml installStateName from NEW to RUNNING.

docker exec -it jenkins bash
sed -i s/NEW/RUNNING/ /var/jenkins_home/config.xml
echo 'false' > /var/jenkins_home/jenkins.install.runSetupWizard
cp /var/jenkins_home/jenkins.install.UpgradeWizard.state /var/jenkins_home/jenkins.install.InstallUtil.lastExecVersion
exit
docker restart jenkins

For reference, this is the command I use to run jenkins:

docker run --rm --name jenkins --network host -u root -d -v jenkins:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean:1.16.0

You will also want to update the config with the Root URL:

echo "<?xml version='1.1' encoding='UTF-8'?><jenkins.model.JenkinsLocationConfiguration><jenkinsUrl>http://<IP>:8080/</jenkinsUrl></jenkins.model.JenkinsLocationConfiguration>" > jenkins.model.JenkinsLocationConfiguration.xml
exit
docker restart jenkins

In case, if you installed/upgraded new versions of jenkins and unable to find admin credentials on server then, ...

if you are using old version of jenkins and on the top of it you are trying to reinstall/upgrade new version of jenkins then,

the files under "JENKINS_HOME", namely -

  1. ${JENKINS_HOME}/jenkins.install.InstallUtil.lastExecVersion
  2. ${JENKINS_HOME}/jenkins.install.UpgradeWizard.state

will cause jenkins to skip the unlock (or admin credentials screen) and webpage directly ask you for username and password. even on server you will not able to find "${JENKINS_HOME}/secrets/initialAdminPassword".

In such case, don't get panic. just try to use old admin user creds in newly installed/upgraded jenkins server.

In simple language, if you have admin creds as admin/admin in old version of jenkins server then, after upgrading jenkins server, the new server won't ask you set password for admin user again. in fact it will use old creds only.

I have found the password in C:\Program Files\Jenkins\jenkins.err. Open jenkins.err text file and scroll down, and you will find the password.

If someone chooses running Jenkins as a Docker container, may face the same problem with me.
Because accessing-the-jenkins-blue-ocean-docker-container is quite different,
Common problem is /var/lib/jenkins/secrets: No such file or directory
You need to access through Docker, the link Jenkins provide is quite helpful.
Except <docker-container-name> maybe not specified, then you may need to use the container ID.

After

docker exec -it jenkins-blueocean bash

or

docker exec -it YOUR_JENKINS_CONTAINER_ID bash

The /var/lib/jenkins/secrets/initialAdminPassword would be accessible.

The password would be there.

I have setup Jenkins using Brew, But when I restarted Mac Jenkins was asking for initialAdminPassword(The screenshot attached in question)

And the problem was it was not generated under sercret directory.

So I'd found the Jenkins process which was running on port: 8080 using: $ sudo lsof -i -n -P | grep TCP and killed it using $ sudo kill 66(66 was process id).

Then I downloaded the latest jenkins .war file from: https://jenkins.io/download/

And executed command: $ java -jar jenkins.war (Make sure you are in jenkins.war directory).

And that's it everything is working fine.

This works well when you are stuck with Docker on Windows and are using Git-Bash

Presuming something like:

# docker run --detach --publish 8080:8080 --volume jenkins_home:/var/jenkins_home --name jenkins jenkins/jenkins:lts

Execute to get the Container ID, for example "d56686cb700d"

# docker ps -l

Now tell Docker to return the password written in the logs for that Container ID:

# docker logs d56686cb700d 2>&1 | grep -A5 -B5 Admin
  • 2>&1 redirects stderr to stdout
  • -A5 includes 5 lines AFTER the line with "Admin" in it
  • -B5 includes 5 lines BEFORE the line with "Admin" in it

Output example:

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

47647383733f4387a0d53c873334b707

This may also be found at: /var/jenkins_home/secrets/initialAdminPassword

*************************************************************
*************************************************************
*************************************************************

Open jenkins.err file in C:\Program Files\Jenkins\. In that file check for a hash key after this line

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

And paste it there in the jenkins prompt. Worked for me.

To solve this problem for docker container in Ubuntu 18.04.5 LTS (Bionic Beaver) - Ubuntu Releases

1- connect to your docker server or ubuntu server witch ssh or other method

2- run sudo docker ps

3- copy the container name parameter ("NAMES")

4- run sudo docker logs "your_parameters_NAMES_VALUES"

5- Find the folowing sentence "Jenkins initial setup is required. An admin user has been created and a password generated. Please use the following password to proceed to installation:" and copy the password

Related