Skip to content

Jenkins

ILLYAKO edited this page Dec 12, 2022 · 22 revisions

Jenkins

https://www.youtube.com/watch?v=pMO26j2OUME&list=PLy7NrYWoggjw_LIiDK1LXdNN82uYuuuiC
jenkins-docker-app

  1. Jenkins Container Setup
  2. Create Multibranch Pipeline with Git Repo
  3. Types of Credentials
  4. Jenkinsfile
    Code -> Commit-> Git Repo-> Trigger build -> Jenkinsfile:test, build, deploy

1. Jenkins Container Setup

Run Jenkins in Docker Container

1.1. Find a Jenkins image in dockerhub

The image 'jenkins/jenkins' should be used.

1.2. Docker run option

  • Expose port 8080 -- By default runs on that port
  • Expose port 50000 -- Master/Slaver Communication
  • Run in detached mode -- run container in the background
  • Bind named volume -- persist data of Jenkins, bind host directory and container directory
  • image version -- latest (jenkins/jenkins:lts)
    .

1.3. Run docker container in CLI

docker run -p 8080:8080 -p 50000:50000 -d -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts

1.3.1. Docker Container list

docker ps

1.3.2. Docker logs

docker logs your_ContainerID

1.3.2.1 An admin user has been created and a password generated

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

3adc1a26a8fd4128a816ca8ba01da498

This may also be found at: /var/jenkins_home/secrets/initialAdminPassword

1.3.3. Open browser localhost:8080 and insert the admin password from the log

1.3.4. Install suggested plugins

1.3.5. Create the First Admin User

IlLya 1234 Illya K ilhaifa@yandex.ru Jenkins URL http://localhost:8080/ Save and Finish

1.3.6. + New Item

  • Freestyle: simple, single tasks e.g. run tests
  • Pipeline: whole delivery cycle e.g. test|build|... for a single branch
  • Multibranch Pipeline : like pipeline for multiple branches

1.3.7. Go to Dashboard -> Manage Jenkins -> Manage Plugins

Updates Available plugins Installed plugins Advanced settings Download progress

2. Create Multibrach Pipeline with Git

2.1 + New Item

Name: "my-pipeline"

2.2. Multibranch Pipeline

Branch Source = Project you want to build
Add Source -> Git
Project Repository - Specify the URL of this remote repository. This uses the same syntax as your git clone command HTTPS.
https://github.com/ILLYAKO/jenkins-docker-app.git
Credentials - > choose created credentials for git repo.
Behaviours -> Add -> Filter by name (with regular expression) -> .* (default means all branches)
Build Configuration Mode -> by Jenkins(default)
Script Path -> Jenkinsfile(default)
Save

2.2.1 Jenkins Credentials

"Credentials" Plugin to store and manage them centrally
Dashboards -> Manage Jenkins -> Manage Credentials -> Credentials -> Jenkins System(Store) -> global(Domains) -> Add Credentials

Kinds:
-Username with password
-GitHub App
-SSH Username with private key
-Secret file
-Secret text
-Certificate

Credential Scopes:
-System: Only available on Jenkins server NOT for Jenkins jobs
-Global: Everywhere accessible
-Project: Limited to project, ONLY with multibranch pipeline (on project page)
ID = Reference for your credentials

2.2.1.1 Create Jenkins Global Credentials

Kind: User with password
Scope: Global (Jenkins, nodes, items, all child items, etc)
Username: global
Password: 1234
ID: global

2.2.1.1 Create Jenkins System Credentials

Kind: User with password
Scope: System (Jenkins and nodes only)
Username: system
Password: 1234
ID: system

2.2.2. Go to the pipeline "my-pipeline" git credentials

kind: username with password
Username: ilhaifa@yandex.ru
password: *******
ID: demo-app-git-credentials

Clone this wiki locally