Skip to content

Instantly share code, notes, and snippets.

@helenhash
Last active November 6, 2024 09:56
Show Gist options
  • Save helenhash/f0a338a07f340f335e483776755d92f3 to your computer and use it in GitHub Desktop.
Save helenhash/f0a338a07f340f335e483776755d92f3 to your computer and use it in GitHub Desktop.

Jenkin Install (With Gitlab Install using Docker)

https://www.jenkins.io/doc/book/installing/docker/

Intro

Jenkins is a self-contained, open source automation server which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software.

Ref: https://bluelight.co/blog/best-ci-cd-tools

CI/CD is a method to frequently deliver apps to customers by introducing automation into the stages of app development. The main concepts attributed to CI/CD are continuous integration, continuous delivery, and continuous deployment.

Jenkins supports both Declarative and Scripted syntax for pipelines.

Install

Installed through native system packages, Docker, or even run standalone by any machine with a Java Runtime Environment (JRE) installed.

With docker

Create a Docker network - to make the other things in same network to interact each other

docker network create gle_network

Jenskin Image

docker run --name great_ganguly -p 8080:8080 -p 50000:50000 jenkins/jenkins:2.387.1-lts-jdk11

Or using docker compose

version: '3.8'

services:
  jenkins:
    image: jenkins/jenkins:lts
    container_name: jenkins
    user: root
    ports:
      - "8080:8080"
      - "50000:50000"
    volumes:
      - jenkins_home:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - my_network

volumes:
  jenkins_home:

networks:
  gle_network:
    external: true

Start

docker-compose up -d

Find password for Jenkins Admin

docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword

docker inspect <container_id>

(Note: Stop and Remove All Containers, Networks, and Volumes (with -v): docker-compose down -v )

For demo purpose, I will create a gitlab in docker to setup code. Remember that gitlab server should join in the same network with jenkins server.

version: '3.8'

services:
  gitlab:
    image: gitlab/gitlab-ee:latest  # For the Enterprise Edition; replace with gitlab/gitlab-ce for Community Edition
    container_name: gitlab
    restart: always
    hostname: 'gitlab.local'  # Set your preferred hostname
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://localhost'  # Set to your server's IP/domain if not running locally
        gitlab_rails['gitlab_shell_ssh_port'] = 2222  # Custom SSH port
    ports:
      - "80:80"         # HTTP
      - "443:443"       # HTTPS (if SSL configured)
      - "2222:22"       # SSH (for Git access)
    volumes:
      - gitlab_config:/etc/gitlab         # GitLab configuration files
      - gitlab_logs:/var/log/gitlab       # Log files
      - gitlab_data:/var/opt/gitlab       # Data files
    networks:
      - gle_network

volumes:
  gitlab_config:
  gitlab_logs:
  gitlab_data:

networks:
  gle_network:
    external: true

To confirm that the GitLab container is connected to gle_network (you can see it also include jenskin container)

docker network inspect my_network

Check jenkin can connect to gitlab

docker exec -it [jenkins-container-id] /bin/bash

ping gitlab

@helenhash
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment