Skip to content

Joska99/jenkins-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jenkins CI labs

Jenkins CI pipeline - build Docker image and Push to DockerHub

Requirements:

  1. Jenkins server
  1. Docker Hub registry
  2. Add your Docker Hub credentials to Jenkins
  3. Install required plugins for Jenkins

Steps:

  1. Configure Jenkins
  • In Jenkins portal: Navigate to "New Item"
  • Give "Name" to item and Chose "Pipeline"
  • You can add description to the pipeline
  • Then chose "Github project" and add Github repo URL
  • Then in "Building Triggers" select "GitHub hook trigger for GITScm polling"
  • In Pipeline select "Pipeline script from SCM", SCM is "Git" add Github repo URL, specify branch, "Script Path" is File name "Jenkinsfile"
  1. Configure GitHub
  • In GitHub repo: Go to "Setting" -> "Webhooks"
  • Payload URL: https://<UR_PUBLIC_IP>:8000/github-webhook/

You need to expose container from localhost to internet
You can use ngrok to achieve this
Run this with ngrok installed

ngrok.exe http 8000

copy link and paste to "Payload URL"
example: https://2966-93-172-72-111.ngrok.io/github-webhook/

  • Content type: "application/json"
  • In "Witch events would trigger?" chose "Just the push event"
  • In "Secret" add API token from Jenkins

in Jenkins portal click on your user name on right top and chose "Configure"
Scroll till "API Token" and generate new

  • Click on "Add webhook"
  1. Finely push some changes and enjoy your pipeline

Add credential to Jenkins:

  1. In Jenkins portal: Go to "Manage Jenkins" -> "Credentials"
  2. click on "global"
  3. Chose "Add credentials"

Docker Hub

  1. Chose "Username with Password"
  2. Fill credentials fields

ID - DockerHub-LG
password - password
username - username

  1. Add description

Add plugins to Jenkins:

  1. In Jenkins portal: Go to "Manage Jenkins" -> "Plugins" -> "Available plugins"
  2. Search for "GitHub Integration Plugin" and install
  3. Search for "Docker Pipeline" and install
  4. Search for "Docker Plugin" and install
Add Docker to jenkins:
  1. In Jenkins portal: Go to "Manage Jenkins" -> "Tools"
  2. Scroll till Docker -> Docker installation
  3. Name - Docker
  4. Install automatically
  5. Chose from Docker.com