Jenkins #
Install #
Docker Compose #
- Make
docker-compose.yml
https://hub.docker.com/_/jenkins
version: '3.8'
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins:latest
privileged: true
ports:
- 8080:8080
volumes:
- ./jenkins_home:/var/jenkins_home
- Run the following.
$ docker-compose up -d
- Confirm the admin initial password.
$ docker logs jenkins | less
*************************************************************
*************************************************************
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
XXXXXXXXXXXXXXXXXXXXXXXXXXX (You can see the password here)
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
or
$ docker container ls
$ docker container exec -it jenkins sh
$ cat /var/jenkins_home/secrets/initialAdminPassword
- Access http://localhost:8080 .
Unlock Jenkins
page.- Enter the admin initial password in
Administrator passwprd
. - Click
Continue
.
- Enter the admin initial password in
Customize Jenkins
page.- Click
Install suggested plugins
(if you are a beginner).
- Click
Create First Admin User
page.- Click
Skip and continuue as admin
.
- Click
CentOS #
sudo wget --no-check-certificate -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
sudo yum install -y jenkins
Jenkins Agent #
Generate SSH keys #
- Generate the private key and the public key.
$ ssh-keygen -t ed25519 -f jenkins_agent
Generating public/private ed25519 key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
$ ls -al jenkins_agent*
jenkins_agent
(private key)jenkins_agent.pub
(public key)
- Confirm the strength.
$ ssh-keygen -l -f jenkins_agent
256 SHA256:XXXXXXXXXXXXXX XXXXXX@XXXXXX (ED25519)
Set the private key in Jenkins #
- Access http://localhost:8080 and login.
- Move to
Dashboad
>Manage Jenkins
>Manage Credentials
. - Click
Jenkins
underStores scoped to Jenkins
. - Click
Global credentials (unrestricted)
. - Click
Add Credentials
in left menu. - Set options.
- Select
SSH Username with private key
. - Select
System (Jenkins and nodes only)
fromScope
.- This means the key can NOT be used for jobs.
- Enter
jenkins_agent
forID
. - Enter
Jenkins agent key
forDescription
. - Enter
jenkins
forUsername
. - Select
Enter directly
ofProvate key
. - Click
Add
. - Enter the contents of the private key.
Your can see it by executing following
cat jenkins_agent
. - Click
OK
.
- Select
Set the public key #
- Add
agent
container todocker-compose.yml
.- https://hub.docker.com/r/jenkins/ssh-agent
- Do NOT enclose the contents of the public key in quotes.
version: '3.8'
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins:latest
privileged: true
ports:
- 8080:8080
volumes:
- ./jenkins_home:/var/jenkins_home
agent:
image: jenkins/ssh-agent:jdk11
privileged: true
container_name: agent
expose:
- 22
environment:
- JENKINS_AGENT_SSH_PUBKEY=ssh-ed25519 XXXXXXXXXXXXXX XXXXXX@XXXXXX (Please write the public key here)
- Restart docker compose.
$ docker-compose down
$ docker-compose up -d
Add new node #
- Access http://localhost:8080 and login.
- Move to
Dashboad
>Manage Jenkins
>Manage Nodes and Clouds
. - Click
New Node
in the menu on the left.- Enter
jenkins_agent
inName
. - Select
Permanent Agent
inType
. - Click
Create
. - Enter
/home/jenkins/agent
inRemote root directory
. - Select
Use this node as much as possible
inUsage
. - Select
Launch agents via SSH
inLaunch method
. - Select
Jenkins(Jenkins Agent Key)
in Credentials. - Select
Non verifying Verification Strategy
inHost Key Verification Strategy
. - Click
Advanced
on the right. - Enter
/usr/local/openjdk-11/bin/java
inJavaPath
. - Click
Save
.
- Enter
- Click
jenkins-agent
in node list. - Click
Log
in the menu on the left. . - It is OK if you see
Agent successfully connected and online
.
Plugin #
- Access http://localhost:8080 and login.
- Move to
Dashboad
>Manage Jenkins
>Manage Plugins
. - Click
Installed
.- Confirm that the following are already installed if you choose
Install suggested plugins
previous step.Mailer
Build With Parameter
- Confirm that the following are already installed if you choose
- Click
Available
.- Find and select the following using a search box.
Rebuilder
Blue Ocean
Office 365 Connector
Maven Integration
Install without restart
- Find and select the following using a search box.
Job #
Pipeline #
e.g.
pipeline {
agent any
stages {
stage('Hello') {
steps {
echo 'Hello'
}
}
stage('World(SKIP)') {
when {
expression { params.SKIP == false }
}
steps {
echo 'World'
}
}
}
}