====== Инструмент Jenkins ====== * [[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]] ===== Установка ===== * [[Сервис JRE]] !!! новая версия, см ниже * [[https://www.jenkins.io/doc/book/installing/linux/|Debian/Ubuntu Long Term Support release]] * [[https://pkg.jenkins.io/debian-stable/]] * !!! В текущей версии устанавливается так: # 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 openjdk-17-jre # 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]] * [[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]] * [[Сервис JRE]] * !!! В текущей версии нужно: Dashboard -> Manage Jenkins -> Security -> TCP port for inbound agents: Random gate# useradd -m -s /bin/bash jenkins * [[Пакет sudo]] Dashboard->Set up an agent->Create a new node Node name: gate Type: Permanent Agent ... Remote root directory: /home/jenkins/ ... Use WebSocket: yes !!! В текущей версии нет ... 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/" ===== Примеры проектов/заданий ===== ==== 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 ... 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 * [[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://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 секунд