How to install jenkins on mac scientifically and rigorously?

How to install jenkins on mac scientifically and rigorously?

write in front

We need to simplify complex things, standardize simple things, streamline standard things, and automate process things.
-----From Xia Huaxia. Chief Scientist of Meituan.

I just happened to be tossing Jenkins with my colleagues recently, and I think this is a "DevOps"-like processing idea.

It's quite fun to play around with Jenkins and various DevOps usage scenarios with my friends.
In the past two days, I have been thinking about installing a jenkins environment on my computer.

I checked the version of jenkins in the production environment 2.263.4. 2.263.4In order to be as consistent as possible with the Jenkins in the production environment, I decided to install this version on my laptop because of my obsessive-compulsive disorder .

1. Struggle before installation

This part is the struggle before installation. If you are not curious, you can skip it and go to the next section.

Because the laptop in my hand is macOS, I first went to the jenkins official website to browse.
Then
go to https://www.jenkins.io/download/lts/macos/ through https://www.jenkins.io/zh/download/.
Insert image description here

This page gives instructions that we can use brew install jenkins-lts@YOUR_VERSIONto install the version I want 2.263.4.

With great anticipation, I decided to give it a try.

$ brew install [email protected]
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
Error: No available formula or cask with the name "[email protected]".
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.

Unfortunately, I found that Homebrew couldn't find this version. Was it the way I opened it that was wrong? It's a bit embarrassing.

Continue reading on the page https://www.jenkins.io/download/lts/macos/,
and you will find the download entrance for the macOS native installation package https://get.jenkins.io in the red box in the picture below. /osx-stable/ .


So I entered the page of https://get.jenkins.io/osx-stable/.

I looked through it and found that the lowest version provided here is jenkins-1.409.1.pkg, and the highest version is . There is no version jenkins-2.235.2.pkgI need , which is embarrassing again.2.263.4

So I returned to the page https://www.jenkins.io/download/lts/macos/. There was a line of text on this page that caught my attention.

Native Installer (deprecated)

Then I realized that the official seems to no longer support installing Jenkins with the new pkg native package.

Also on the official blog page
Jenkins macOS native installer deprecation: https://www.jenkins.io/blog/2019/11/25/macos-native-installer-deprecation/ ,
the jenkins macOS native installer is indeed deprecated instruction of.

There is a description on the webpage that I took a screenshot. It roughly means that as an alternative to the abandoned jenkins macOS native installation program, under mocOS you can directly use the War package or use Homebrew to install and manage Jenkins.

Insert image description here

There are two Homebrew formulas for Jenkins: jenkins for Weekly releases and jenkins-lts for LTS ones.

The official blog states that brew install jenkinsthe latest weekly version of Jenkins can be installed.
Use brew install jenkins-ltsthe latest LTS version of Jenkins installed.
It is also pointed out that you can brew install jenkins@YOUR_VERSIONinstall specific weekly releases of Jenkins using.

So now according to the official blog

We can use brew install jenkins-ltsthe latest LTS version of Jenkins installed.

brew install jenkins-lts@YOUR_VERSIONA specific LTS version of Jenkins can be installed.

You can use brew install jenkinsthe latest weekly version of jenkins installed.

It is possible to brew install jenkins@YOUR_VERSIONinstall specific weekly releases of jenkins.

At the beginning of the article, we already tried brew install [email protected]to install it, but it didn't work at all.
Now I'm going to try brew install [email protected]to install it.

$ brew install [email protected]
Updating Homebrew...
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
Error: No available formula or cask with the name "[email protected]".
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.

It also cannot be installed normally.

Well, I wanted to be lazy, but it turned out. . .

Hahaha, curiosity killed the cat, hahahaha

Then let’s install it obediently using the war package method.

2. Install jenkins

The entrance to downloading the war package is on the download page of the official website, which is the location circled by me in the picture below.

After entering, I found that all LTS versions from 1.409.1to 2.289.1to can be downloaded here, including 2.263.4the version I want.

At this time, we can select the link corresponding to the specified version and enter the corresponding page to download directly. Of course, I chose 2.263.4 here .

We can also choose to download using the command below.

wget https://get.jenkins.io/war-stable/2.263.4/jenkins.war

Program account creation

# 创建组
sudo dscl . create /Groups/jenkins gid 5555
# 创建用户
sudo dscl . create /Users/jenkins uid 7777
sudo dscl . create /Users/jenkins gid 5555 
sudo dscl . create /Users/jenkins shell /bin/bash
# 修改用户的密码
sudo passwd jenkins
# 创建用户的home目录
sudo  mkdir /Users/jenkins
# 用户的home目录宿主
sudo chown -R jenkins:jenkins /Users/jenkins
# 声明用户的home目录
sudo dscl . create /Users/jenkins home /Users/jenkins

macOS can use dscl to manage users. To learn more, you can click

[Tips] Use the dscl command line to manage user
viewing under macOS.

Prepare the running directory of jenkins

# 切换当前用户为 jenkins
$ su - jenkins
jenkins$ whoami
jenkins

# 准备程序安装包目录
jenkins$ pwd
/Users/jenkins
jenkins$ mkdir soft
jenkins$ ls
soft
jenkins$ cd soft/
jenkins$ wget https://get.jenkins.io/war-stable/2.263.4/jenkins.war
jenkins$ ls
jenkins.war

# 准备程序运行目录
jenkins$ cd /Users/jenkins/
jenkins$ mkdir 2.263.4
jenkins$ ls
2.263.4	soft

Start jenkins

jenkins$ java -jar -Xmx4096m -DJENKINS_HOME=/Users/jenkins/2.263.4 /Users/jenkins/soft/jenkins.war --httpPort=9999
Running from: /Users/jenkins/soft/jenkins.war
webroot: System.getProperty("JENKINS_HOME")
.
.
.
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

ecc86b654f3a4e0bbeb4e2df962839a0

This may also be found at: /Users/jenkins/2.263.4/secrets/initialAdminPassword
.
.
.

During the startup process, we can see that the initialization password of the Jenkins administrator user will be written in
${JENKINS_HOME}/secrets/initialAdminPassword.
My experiment is in /Users/jenkins/2.263.4/secrets/initialAdminPasswordthis file. Your experiment process may be slightly different.

3. First introduction to jenkins

Getting Started

After jenkins is started, we visit http://localhost:${port}/ (my port here is 9999) to enter the jenkins page.

When you visit for the first time, you can see the getting started guide of jenkins, and then you will see the following interfaces in sequence.


Insert image description here

Insert image description here

At this time, we can choose to use the admin account to continue (the admin user is automatically created during jenkins installation) or we can choose to create a new admin user. Here we choose to use the existing admin account to continue.

You have skipped the step of creating the admin user. To log in use the username "admin" and the administrator password used to access the installation wizard.


Click to start using jenkins

Insert image description here

The middle part of the homepage mainly provides some links that newbies to Jenkins may use. The first one is the task creation link.

Then there is the agent settings link,
Insert image description here
followed by the cluster configuration link.

Finally, there are links to relevant documentation on distributed construction.
https://www.jenkins.io/redirect/distributed-builds
https://wiki.jenkins.io/display/JENKINS/Distributed+builds

main menu

On the left side of the home page are links to commonly used function menus. In order, they are "New Item", "User List", "Build History", "Manage Jenkins", "My Views", etc.
Let's take a look at "Manage Jenkins" first, click to enter.

Some plugins cannot be loaded due to missing dependencies. To restore the functionality provided by these plugins, you need to fix these issues and restart Jenkins.

According to the prompts on the page, we need to restart Jenkins so that the plug-in can take effect, and then we enter it in the browser http://localhost:9999/restart.

After clicking "Yes", you will stay on the "Restarting" page for a moment.

After the Jenkins restart is complete, the page will automatically jump to the login page.
Insert image description here

Enter admin and its password on the login page (the user automatically created during the Jenkins installation, the password information is in the startup log) and enter the Jenkins homepage again. It is found that the menu display on the page is somewhat different from before the restart. It should be localized after the restart
. The plug-in has taken effect and the menu is displayed in Chinese.

Entering the "System Management" menu again, we also found that the menu on the page was displayed in Chinese, and the red prompt before restarting had disappeared.

Job Demo

With Jenkins ready, let's quickly run a job and try it out. The example is very simple, just use jenkins job to print out "jenkins hello world".

Create job.
Insert image description here

Configure job.

Execute the job.

Job execution record list.

Job execution log.

The job executes normally and prints out "jenkins hello world".

Management password change (important)

Finally, since we have been using the password automatically set during Jenkins installation, this password is output in the installation log above.

It is also saved in ${JENKINS_HOME}/secrets/initialAdminPasswordthis file.

Therefore, there will be certain security risks. In order to avoid unnecessary trouble, we need to change the admin password here.
The operation steps are to find "Manage Users" in "System Management"
Insert image description here

Click the "Manage Users" link to enter the "User List", find the admin user in the list of all users given, and click its settings button.

Enter the admin user's information update page, scroll down to the password setting area, enter the new password information and submit it.

Insert image description here
Re-visit http://localhost:9999/and enter the new password of the admin user in the redirected login page. If you can log in normally, it means that the password of the admin user has been updated successfully.

Finally, I don’t know if my opening method is wrong, but I can’t use Homebrew to install the specified version of Jenkins.
How did you install it? Looking forward to your sharing!

friendly reminder

If you install an older version, you may not be able to install appropriate plug-ins during subsequent use. It is not recommended to install an older version unless necessary.

Guess you like

Origin blog.csdn.net/uwoerla/article/details/127033098