Инструмент Jenkins
Установка
!!! Обратитесь к преподавателю !!!
# wget -O /usr/share/keyrings/jenkins-keyring.asc https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
# echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
# apt-get update
# apt-get install fontconfig default-jre-headless
# apt-get install jenkins
Смена порта
server# systemctl stop jenkins
server# systemctl edit jenkins
[Service]
Environment="JENKINS_PORT=8081"
server# systemctl start jenkins
server# systemctl status jenkins
Dashboard -> Manage Jenkins -> System
Jenkins URL: http://server.corpX.un:8081/
Подключение
Подключение агента
gate# useradd -m -s /bin/bash jenkins
Агент подключается к контроллеру
Dashboard->Set up an agent->Create a new node
Node name: gate
Type: Permanent Agent
...
Remote root directory: /home/jenkins/
...
Способ запуска
Запустить агент, подключив его к контроллеру
...
gate# su - jenkins
Копируем команды, указанные на странице нового агента:
jenkins@gate:~$ curl -sO http://server.corpX.un:8081/jnlpJars/agent.jar
jenkins@gate:~$ java -jar agent.jar -jnlpUrl http://server.corpX.un:8081/computer/gate/jenkins-agent.jnlp -secret NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN -workDir "/home/jenkins/"
...
INFO: Connected
Запуск агента через SSH
gate# passwd jenkins
Dashboard->Set up an agent->Create a new node
Node name: gate
Type: Permanent Agent
...
Remote root directory: /home/jenkins/
...
Способ запуска
Launch Agent via SSH
...
Host: gate
Credentials ...
Host Key Verification Strategy: Non ...
...
Примеры проектов/заданий
Freestyle projects
Enter an item name:
dhcp freestyle project
...
Restrict where this project can be run:
gate
...
Source Code Management:
Git:
Repository URL: http://server.corpX.un:3000/student/dhcp.git
...
Branch Specifier: */*
...
Build Steps
Execute shell:
make test
Execute shell:
sudo make install
...
Dashboard -> dhcp freestyle project
Build Now
Pipeline
Enter an item name:
dhcp pipeline
...
Pipeline
Pipeline script from SCM
Repository URL: http://server.corpX.un:3000/student/dhcp.git
Branches to build: */*
В SCM GitLab/GitHub/Gitea:
New File: Jenkinsfile
pipeline {
agent {
node {
label 'gate'
}
}
stages {
stage('Test') {
steps {
sh 'make test'
}
}
stage('Deploy') {
steps {
sh 'sudo make install'
}
}
}
}
Webhooks
Manage Jenkins -> Manage Plugins -> Available -> Gitea
Manage Jenkins -> Configure System -> Gitea Servers
Name: server
Server URL: http://server.corpX.un:3000/
Manage hooks
Jenkins Credentials Provider: Jenkins
Login: student
...
Freestyle dhcp
или
Pipeline dhcp
Configure
Poll SCM: yes
Gitea
Project->Setings->Webhooks
Должен появиться Target URL и работать Test Delivery
Задержка, примерно, 30 секунд