====== Инструмент Jenkins ======
* [[https://www.jenkins.io/doc/book/system-administration/admin-password-reset-instructions/|Reset the administrator password]]
===== Установка =====
* [[Сервис JRE]]
* [[https://www.jenkins.io/doc/book/installing/linux/|Debian/Ubuntu Long Term Support release]]
* [[https://pkg.jenkins.io/debian-stable/]]
* [[https://stackoverflow.com/questions/63635421/install-suggested-plugins-for-jenkins|Install suggested plugins for 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
==== Смена порта ====
* Может понадобиться, если на этой-же системе разворачивается GitLab
* [[https://askubuntu.com/questions/1398910/changed-jenkins-port-doesnt-applied|Changed Jenkins port doesn't applied]]
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/
===== Подключение =====
* [[http://server.corpX.un:8081/]]
===== Подключение агента =====
* [[https://medium.com/@med446/setting-up-a-jenkins-slave-a7000358c557|Setting up a Jenkins Agent]]
* [[Сервис JRE]]
gate# useradd -m -s /bin/bash jenkins
* [[Пакет sudo]]
==== Агент подключается к контроллеру ====
* !!! В текущей версии нужно: Dashboard -> Manage Jenkins -> Security -> TCP port for inbound agents: Random
* Требуется [[https://plugins.jenkins.io/instance-identity/|Instance Identity]] plugin
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
* [[https://www.jenkins.io/blog/2022/12/27/run-jenkins-agent-as-a-service/|Create a new Jenkins node, and run your Jenkins agent as a service]]
* [[Управление сервисами в Linux#Система загрузки Systemd]]
==== Запуск агента через SSH ====
* Требуется [[https://plugins.jenkins.io/ssh-slaves/|SSH Build Agents]] plugin
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 ====
* !!! В первый раз обязательно запустить "вручную"
* [[https://www.jenkins.io/doc/book/pipeline/getting-started/|Getting started with 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: */*
* [[https://www.jenkins.io/doc/book/pipeline/syntax/|Pipeline Syntax]]
В 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 ====
* [[https://hevodata.com/learn/gitlab-webhook-jenkins-integration/|GitLab Webhook Jenkins Integration: Automating Jobs Simplified 101]]
* [[https://gcube.wiki.gcube-system.org/gcube/Gitea/Jenkins:_Setting_up_Webhooks|Gitea/Jenkins: Setting up Webhooks]]
Manage Jenkins -> Manage Plugins -> Available -> Gitea
* [[Инструмент Gitea#Файл конфигурации]] Gitea: ALLOWED_HOST_LIST
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 секунд