docker-compose installs jenkins jdk11, packages jdk8, and configures the whole process of gitlab

Updated on November 21, 2022,
updated part [7.docker-compose.yml update]

0. Directory file

Pay attention to configuring 777 permissions for the jenkins_data directory.

chmod +777 jenkins_data

Insert image description here

1.jenkins 的docker-compose.yml

I used to use the image jenkins/jenkins:2.377-jdk11 and it kept having problems, so I changed it to the bitnami image. Then I changed it to version 2.378-jdk11 and it worked again. For the specific docker-compose.yml, please see the article about the change. Chapter 7

version: '3.8'
services:
  jenkins:
    container_name: jenkins
    image: docker.io/bitnami/jenkins:2
    privileged: true
    user: root
    ports:
      - '8081:8080'
    environment:
      - JENKINS_PASSWORD=bitnami
    volumes:
      - ./jenkins_data:/bitnami/jenkins

2. After installation, the default user name is user and the password is bitnami.

3. Configure the container with ssh provided by gitlab

Each of the following steps requires action

通过root用户进入容器
sudo docker exec -it -u root 7f0deeb2cfc6 /bin/bash
在/root目录下创建.ssh目录
cd /root
mkdir .ssh
生成公钥秘钥
ssh-keygen -t rsa -C "你的gitlab的邮箱"
=================================
root@7f0deeb2cfc6:/root/.ssh# ls
id_rsa  id_rsa.pub
==================================

Copy the public key to gitlab and
Insert image description here
try the clone code in the container. It prompts that the CA certificate verification failed.
Insert image description here
Configure the authentication to false.

git config --global http.sslverify false
git config --global https.sslverify false

4. Configure credentials on the jenkins panel [in the form of username and password]

Insert image description here

5. Project git warehouse configuration

Insert image description here
After building it, the corresponding code will be in the workspace.
Insert image description here

6. Configure jdk8 to package and compile the jar package of jdk8

Check that the Linux version of the container is red hat, and install the corresponding jdk1.8

sudo docker exec -it -u root 7f0deeb2cfc6 /bin/bash
cat /proc/version
##Linux version 3.10.0-1160.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Mon Oct 19 16:18:59 UTC 2020

Go to the official website to download jdk8 https://www.oracle.com/cn/java/technologies/downloads/
Insert image description here
and extract it to the directory corresponding to the server mounted by my container.
Insert image description here
At this time, there will be the corresponding decompressed directory in the container
Insert image description here
and then go Jenkins configures the jdk directory and it's OKInsert image description here

Then install a jdk parameter plug-in
Insert image description here
to parameterize the build configuration jdk1.8
Insert image description here

7.docker-compose.yml updated

The following docker-compose is also available. For other steps, just refer to 1-6 above.

version: '3.8'
services:
  docker_jekins_2.378:
    image: jenkins/jenkins:2.378-jdk11
    container_name: docker_jekins_2.378
    user: root
    ports:
      - "8081:8080"
    expose:
      - "50000"
      - "8080"
    privileged: true
    restart: unless-stopped
    volumes:
      - ./jenkins_data:/var/jenkins_home

Guess you like

Origin blog.csdn.net/weixin_42581660/article/details/127861621