The inspiration for writing this article comes from the recent failure of Jenkins deployment of the company for various reasons. In the case of a very busy project, I have to spend half a day every day to check the problems on Jenkins. So we decided to build Jenkins on our front-end server for test deployment. And deployed to the front-end server. The article is written at the same time, trampling all over the pit. I don’t know if you will also encounter these problems. Anyway, I’ve written the solution in it.
The main content of this paper is to introduce the construction and use of Jenkins. As for whether to install Jenkins on the server or through docker in this article, it is not very important. By default, readers will use docker. If you don’t know it very well
dockerThis article is published in my blog at the same time
docker pull docker.io/jenkins/jenkins:latest
Use after successful installation
docker imagesView image
github docker images REPOSITORY TAG IMAGE ID CREATED SIZE jenkins/jenkins latest 59f8784e08ee 2 days ago 619MB
Before starting Jenkins, you need to create a Jenkins configuration directory and mount it to the Jenkins directory in the docker
Create a new folder like mine
And authorize the folder
sudo chown -R 1000 /Users/zhouatie/Desktop/github/front-end/practise-jenkins
There’s a magic point here. It’s said to authorize online, so I authorized it, but still prompted
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions. Later, I created a new folder without authorization. Check stackoverflow. A friend in stackoverflow doesn’t use authorizing even if he encounters the same problem.
Execute the following command to build the container
docker run -itd -p 8080:8080 -p 50000:50000 --name jenkins -v /Users/zhouatie/Desktop/github/front-end/practise-jenkins:/var/jenkins_home docker.io/jenkins/jenkins:latest
docker psView the container started in the background
➜ front-end git:(master) ✗ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3385ad0e42fe jenkins/jenkins:latest "/sbin/tini -- /usr/…" 5 minutes ago Up 5 minutes 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp jenkins
You can see that the Jenkins container has been started successfully. Visit the next page at this time. Browser input
You can see the following interface
At this time, we can go to the folder where we just managed the data volume (my local name is
catYou can see the output in this file
28023d3751214bd6aadc0dd83c168325, copy the password to the administrator password input box and click continue.
After a long time of loading, I have a feeling of uncertainty. The results showed that Jenkins was offline. So I began to search the Internet again for offline problems when installing the new version of Jenkins
- Browser input
You can see it at the bottom
- Replace the address in the screenshot with
http://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/current/update-center.jsonThis proxy server
http://localhost:8080The page is as follows
Click to install the recommended plug-in
The results are as follows
Then I started again
Results according to the previous steps failed, the author suggested restart, OK, restart on restart, execute
docker restart jenkins
Finally, I successfully entered the download page again.
The installation is really very slow, and I’m very anxious. I don’t know if it’s the reason for docker. Because the article is written directly while operating. I wonder if I want to go directly across the installation interface and open Jenkins running on the front-end server
Before he told me to fail completely, I started again
jenkinsAfter the container, select the plug-in of your choice. After entering the page, you can download it in the following screenshot. I check all the above recommendations and download them. The result is very fast.
- After installing the plug-in and restarting, you can see the following interface
- Click new task in the upper right corner
- Choose the first free style mode
- After confirmation, enter the following page and click Configure
- Because some plug-ins failed to install, I’ll take the screenshot of Jenkins configuration interface as an example
- Parametric construction: parametric construction is mainly mentioned here. The corresponding values can be obtained from the following [build] execution shell to obtain the parameters manually selected or filled in by the user during deployment.
Source code managementThe main thing is to let Jenkins pull code from your git repository,
credentialsYou need to select an account with the warehouse permission. You can try it manually
Building triggersIt means trigger conditions, such as
jenkinsDeployment. Please refer to
structure: This is the key point. Here you can execute your script. For example, if you are a Vue project, you can get the installation dependency according to the above parameterized configuration. Look at my picture
shellScript, very easy to understand.