Docker builds Jenkins server from scratch

Time:2021-4-17

preface

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 welldockerThis article is published in my blog at the same time

Install Jenkins

docker pull docker.io/jenkins/jenkins:latest

Use after successful installationdocker 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/Users/zhouatie/Desktop/github/front-end/practise-jenkins

And authorize the foldersudo 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 promptedCan 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

implementdocker 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 inputlocalhost:8080

You can see the following interface

Docker builds Jenkins server from scratch

At this time, we can go to the folder where we just managed the data volume (my local name is/Users/zhouatie/Desktop/github/front-end/practise-jenkins/secrets/initialAdminPassword),catYou can see the output in this file28023d3751214bd6aadc0dd83c168325, 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

Solution steps

  1. Browser inputhttp://localhost:8080/pluginManager/advanced

    You can see it at the bottom

    Docker builds Jenkins server from scratch

  2. Replace the address in the screenshot withhttp://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/current/update-center.jsonThis proxy server

Refresh againhttp://localhost:8080The page is as follows

Docker builds Jenkins server from scratch

  1. Click to install the recommended plug-in

    The results are as follows

    Docker builds Jenkins server from scratch

    Then I started againgoogleIt’s too late. Found a solution to the problem of no such plugin: cloudbees folder when Jenkins is installed

    Results according to the previous steps failed, the author suggested restart, OK, restart on restart, executedocker 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

Docker builds Jenkins server from scratch

Before he told me to fail completely, I started againgoogleIt’s too late. There’s no way. It’s too hard. So I rebooted onejenkinsAfter 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.

Docker builds Jenkins server from scratch

  1. After installing the plug-in and restarting, you can see the following interface

    Docker builds Jenkins server from scratch

structure

  1. Click new task in the upper right corner

Docker builds Jenkins server from scratch

  1. Choose the first free style mode

Docker builds Jenkins server from scratch

  1. After confirmation, enter the following page and click Configure

Docker builds Jenkins server from scratch

  1. Because some plug-ins failed to install, I’ll take the screenshot of Jenkins configuration interface as an example

Docker builds Jenkins server from scratch

  • 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 asgitOnwebhookTo triggerjenkinsDeployment. Please refer togoogle
  • 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 pictureshellScript, very easy to understand.

Recommended Today

Quickly use the latest 15 common APIs of vue3

Before that, I wrote a blog to introduce the new features of vue3. I had a brief understanding of the features of vue3, and at the end of the article, I gave you a little experience in vue3Compsition APISimple use of Address of last article: follow Youda’s steps and experience the new features of vue3 […]