1. Preface

  • Master主要做任务调度,Agent专用于任务执行;

  • 尽量不要使用其它lts版本,容易引发异常,含无法安装插件
    UnknownHostException: updates.jenkins.io

2. Dir and Permission

mkdir -p /elf/jenkins/jenkins-master \
	&& chmod 777 -R /elf/jenkins/jenkins-master

3. Run Container

docker run \
	--name jenkins-master \
	--privileged=true \
	--net network-common \
	-p 8080:8080 -p 50000:50000 \
	--volume /elf/jenkins/jenkins-master:/var/jenkins_home \
	-e JAVA_OPTS="-Dorg.apache.commons.jelly.tags.fmt,timeZone='Asia/Shanghai'" \
	-itd jenkins/jenkins:lts

4. Note Password

docker logs -f jenkins-master

5fe80e2a13e248388a46a6921a70621e

/var/jenkins_home/secrets/initialAdminPassword

6. Jenkins初始化

  • 选择自定义安装插件,选择最上面的None取消所选,
    然后选择Language两项:locale和localization-zh-cn

  • 创建用户:admin - admin

  • 获得Jenkins URL:http://192.168.0.123:8080/

docker exec jenkins-master cat \
	/var/jenkins_home/secrets/initialAdminPassword

docker stop jenkins-master && docker remove jenkins-master

7. Plugin Source

8. Agent Slave

  • 进jenkins-master容器,得知jdk版本为17,因任何agent节点都需使用;

wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz

tar -zxvf jdk-17_linux-x64_bin.tar.gz -C /elf/ && mv ./jdk-17.0.9 ./jdk17

vim /etc/profile

export JAVA_HOME=/elf/jdk17
export PATH=$PATH:$JAVA_HOME/bin

source /etc/profile
  • executor number(执行器):执行一个任务会占用一个执行器;

  • label:标签代表一组,如我们可创建10个节点,但共属一个标签,
    运行时会在此10个节点中随机选取节点来运行任务;

  • 登录后 ⇒ Manage Jenkins ⇒ Nodes ⇒ New Node
    节点有动态节点和静态节点之分,此处为创建普通节点,动态节点会用到旁边的Clouds;

  • 节点名称:jenkins-agent,类型:Permanent Agent,

  • 执行器数设为5,远程根目录:/elf/jenkins/jenkins-agent-01

  • 标签设置为:jenkins-agent,启动方式(Launch Method):Java Web;

  • Custom WorkDir Path:/elf/jenkins/jenkins-agent

  • 点击节点,运行Agent命令并保存秘密存储到文件,在/elf/jenkins目录执行以下命令;

echo 25aef4033456fff46e0a49e282b340ebd93e8309b5413852f06fb01f8be61a1d > secret-file
curl -sO http://192.168.0.123:8080/jnlpJars/agent.jar
java -jar agent.jar -jnlpUrl http://192.168.0.123:8080/computer/jenkins%2Dagent%2D01/jenkins-agent.jnlp \
	-secret @secret-file -workDir "/elf/jenkins/jenkins-agent"
  • agent连接到master后,编写脚本后台启动agent

vim /elf/jenkins/start-agent.sh

echo 25aef4033456fff46e0a49e282b340ebd93e8309b5413852f06fb01f8be61a1d > secret-file
curl -sO http://192.168.0.123:8080/jnlpJars/agent.jar
nohup java -jar agent.jar -jnlpUrl http://192.168.0.123:8080/computer/jenkins%2Dagent%2D01/jenkins-agent.jnlp \
	-secret @secret-file -workDir "/elf/jenkins/jenkins-agent" >>/dev/null &
  • 在Jenkins Pipeline中,流水线由多阶段stage组成,如:构建、测试、部署等

  • Jenkins每个Agent节点都应有相对应的环境,如Jdk,Maven,Gradle等来执行Java程序;

  • Agent节点可分为静态和动态节点,静态节点是固定虚拟机或容器,动态节点是随任务的构建自动创建agent节点;

9. External Plugin

  • Pipeline;

  • Strict Crumb Issuer;

  • Role-based Authorization Strategy;

  • Credentials;

  • Blue Ocean;

10. Data Dir

Entry Memo

caches

系统缓存数据

jobs

Jenkins项目作业

nodes

Jenkins Agent节点信息

secrets

秘钥信息

userContent

类web站点目录,可上传文件

workspace

默认的工作目录

fingerprints

指纹验证信息

logs

日志信息

plugins

插件相关配置

updates

插件更新目录

users

jenkins系统用户目录