安装部署jenkins [五]
Freestyle project
自由风格项目,Jenkins最主要的项目类型
General
项目基本配置
项目名称、描述、参数、禁用项目、并发构建、限制构建默认node等等
Source code Management
代码库信息,支持Git,Subversion等
Build Triggers
构建触发方式
周期性构建,Poll SCM,远程脚本触发构建,其他项目构建结束后触发等
Build Environment
构建环境相关设置
构建前删除workspace,向console输出添加时间戳,设置构架按名称,插入环境变量等
Build
项目构建任务
添加1个或者多个构建步骤
Post-build Actions
构建后行为
Artifact归档,邮件通知,发布单元测试报告,触发下游项目等
Maven Project
Maven项目专用,类似Freestyle,更简单
Multi-configuration Project
多配置项目,适合需要大量不同配置(环境,平台等)构建
Pipeline
流水线项目,适合使用pipeline(workflow)插件功能构建流水线任务,或者使用Freestyle project 不容易实现的复杂任务
Multibranch Pipeline
多分支流水线项目,根据SCM仓库中的分支创建多个Pipeline项目



增加构建节点




可以查看控制台输出信息
Started by user root Building in workspace /var/jenkins_home/workspace/my-freestyle-job [my-freestyle-job] $ /bin/sh -xe /tmp/jenkins3834169033737812985.sh + env JENKINS_HOME=/var/jenkins_home JENKINS_UC_EXPERIMENTAL=https://updates.jenkins.io/experimental RUN_CHANGES_DISPLAY_URL=http://106.2.3.245:8080/job/my-freestyle-job/1/display/redirect?page=changes HOSTNAME=031445a34981 NODE_LABELS=master HUDSON_URL=http://106.2.3.245:8080/ SHLVL=0 HOME=/var/jenkins_home BUILD_URL=http://106.2.3.245:8080/job/my-freestyle-job/1/ HUDSON_COOKIE=528fa394-4e44-46a4-8e48-7200ed5709a1 JENKINS_SERVER_COOKIE=85059fa3dd0b75b8 JENKINS_UC=https://updates.jenkins.io WORKSPACE=/var/jenkins_home/workspace/my-freestyle-job JAVA_VERSION=8u151 NODE_NAME=master CA_CERTIFICATES_JAVA_VERSION=20170531+nmu1 EXECUTOR_NUMBER=0 TINI_SHA=6c41ec7d33e857d4779f14d9c74924cab0c7973485d2972419a3b7c7620ff5fd JENKINS_VERSION=2.60.3 BUILD_DISPLAY_NAME=#1 HUDSON_HOME=/var/jenkins_home JOB_BASE_NAME=my-freestyle-job JAVA_DEBIAN_VERSION=8u151-b12-1~deb9u1 PATH=/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin BUILD_ID=1 BUILD_TAG=jenkins-my-freestyle-job-1 LANG=C.UTF-8 JENKINS_URL=http://106.2.3.245:8080/ JOB_URL=http://106.2.3.245:8080/job/my-freestyle-job/ BUILD_NUMBER=1 RUN_DISPLAY_URL=http://106.2.3.245:8080/job/my-freestyle-job/1/display/redirect JENKINS_SLAVE_AGENT_PORT=50000 HUDSON_SERVER_COOKIE=85059fa3dd0b75b8 JOB_DISPLAY_URL=http://106.2.3.245:8080/job/my-freestyle-job/display/redirect JOB_NAME=my-freestyle-job COPY_REFERENCE_FILE_LOG=/var/jenkins_home/copy_reference_file.log PWD=/var/jenkins_home/workspace/my-freestyle-job TINI_VERSION=0.14.0 + echo hello world! hello world! + echo /bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin Finished: SUCCESS
构建好后job后生成
[root@linux-node2 ~]# cd /root/data/jenkins/jobs/ [root@linux-node2 jobs]# ll total 0 drwxr-xr-x 3 1000 1000 96 Aug 27 09:29 my-freestyle-job
jenkins配置好保存在xml文件中,把这个共享后运行,就能使用。
<?xml version='1.0' encoding='UTF-8'?> <project> <actions/> <description></description> <keepDependencies>false</keepDependencies> <properties> <com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty plugin="gitlab-plugin@1.5.1"> <gitLabConnection></gitLabConnection> </com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty> </properties> <scm class="hudson.scm.NullSCM"/> <canRoam>true</canRoam> <disabled>false</disabled> <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> <triggers/> <concurrentBuild>false</concurrentBuild> <builders> <hudson.tasks.Shell> <command>env echo "hello world!" echo "$PATH"</command> </hudson.tasks.Shell> </builders> <publishers/> <buildWrappers/> </project>
my-freestyle-job目录下的文件
[root@linux-node2 my-freestyle-job]# ll total 8 drwxr-xr-x 3 1000 1000 152 Aug 27 09:29 builds -rw-r--r-- 1 1000 1000 889 Aug 27 09:26 config.xml 配置 lrwxrwxrwx 1 1000 1000 22 Aug 27 09:29 lastStable -> builds/lastStableBuild lrwxrwxrwx 1 1000 1000 26 Aug 27 09:29 lastSuccessful -> builds/lastSuccessfulBuild -rw-r--r-- 1 1000 1000 2 Aug 27 09:29 nextBuildNumber [root@linux-node2 my-freestyle-job]# cd builds/ [root@linux-node2 builds]# ll 查看构建次数 total 0 drwxr-xr-x 2 1000 1000 52 Dec 7 18:54 1 lrwxrwxrwx 1 1000 1000 2 Aug 27 09:23 lastFailedBuild -> -1 lrwxrwxrwx 1 1000 1000 1 Aug 27 09:29 lastStableBuild -> 1 lrwxrwxrwx 1 1000 1000 1 Aug 27 09:29 lastSuccessfulBuild -> 1 lrwxrwxrwx 1 1000 1000 2 Aug 27 09:24 lastUnstableBuild -> -1 lrwxrwxrwx 1 1000 1000 2 Aug 27 09:24 lastUnsuccessfulBuild -> -1 -rw-r--r-- 1 1000 1000 0 Aug 27 09:22 legacyIds [root@linux-node2 builds]# cd 1/ [root@linux-node2 1]# ll total 12 -rw-r--r-- 1 1000 1000 1468 Aug 27 09:29 build.xml -rw-r--r-- 1 1000 1000 6 Aug 27 09:29 changelog.xml -rw-r--r-- 1 1000 1000 2121 Aug 27 09:29 log 可以查看日志信息
Jenkins是一套master/slave分布式的架构。最佳实践不要再master上做很多工作,Jenkins很消耗资源。(大内存,高IO的机器)不要在上面跑job

节点管理
系统配置credentials管理
SSH Username with private key
新增Slave





需要安装jdk
yum install -y java-1.8.0-openjdk-devel

配置非本机的从节点192.168.56.11
[root@linux-node1 ~]# ssh-keygen -t rsa -C root@devops.com [root@linux-node1 ~]# ll ~/.ssh/ total 8 -rw------- 1 root root 1679 Dec 4 17:55 id_rsa -rw-r--r-- 1 root root 397 Dec 4 17:55 id_rsa.pub [root@linux-node1 ~]# chmod 755 id_rsa [root@linux-node1 ~]# ll total 20 -rwxr-xr-x 1 root root 1679 Dec 4 17:55 id_rsa -rw-r--r-- 1 root root 397 Dec 4 17:55 id_rsa.pub -rw-r--r-- 1 root root 175 Dec 4 18:10 known_hosts [root@linux-node1 ~]# yum install -y java-1.8.0-openjdk-devel



出现错误参考---->slave节点参考

查看构建历史

slave构建结果传回master上
在节点192.168.56.11上构建的job没有结果 [root@linux-node1 ~]# ll /root/jenkins_home/ total 704 drwxr-xr-x 2 root root 6 Dec 4 18:19 jdk -rw-r--r-- 1 root root 719269 Dec 4 18:27 slave.jar drwxr-xr-x 3 root root 29 Dec 8 16:25 workspace [root@linux-node1 ~]# ll /root/jenkins_home/workspace/ total 0 drwxr-xr-x 2 root root 6 Dec 8 16:25 my-freestyle-job [root@linux-node1 ~]# ll /root/jenkins_home/workspace/my-freestyle-job/ total 0 因为所有结果都传回到master上来 [root@linux-node2 ~]# ll /root/data/jenkins/jobs/my-freestyle-job/builds/ total 0 drwxr-xr-x 2 1000 1000 52 Dec 7 18:54 1 drwxr-xr-x 2 1000 1000 52 Dec 8 01:25 2 drwxr-xr-x 2 1000 1000 52 Dec 8 01:27 3 lrwxrwxrwx 1 1000 1000 2 Aug 27 09:23 lastFailedBuild -> -1 lrwxrwxrwx 1 1000 1000 1 Dec 8 01:27 lastStableBuild -> 3 lrwxrwxrwx 1 1000 1000 1 Dec 8 01:27 lastSuccessfulBuild -> 3 lrwxrwxrwx 1 1000 1000 2 Aug 27 09:24 lastUnstableBuild -> -1 lrwxrwxrwx 1 1000 1000 2 Aug 27 09:24 lastUnsuccessfulBuild -> -1 -rw-r--r-- 1 1000 1000 0 Aug 27 09:22 legacyIds
构建一个job



在slave节点查看信息,整个过程的内容是在slave上,所有的结果会传到master上
[root@linux-node1 ~]# ll /root/jenkins_home/workspace/my-freestyle-job/ total 8 drwxr-xr-x 4 root root 78 Dec 8 16:42 account-captcha drwxr-xr-x 4 root root 78 Dec 8 16:42 account-email drwxr-xr-x 4 root root 78 Dec 8 16:42 account-persist drwxr-xr-x 4 root root 78 Dec 8 16:42 account-service drwxr-xr-x 4 root root 95 Dec 8 16:42 account-web -rw-r--r-- 1 root root 3276 Dec 8 16:42 pom.xml -rw-r--r-- 1 root root 670 Dec 8 16:42 README.md
现在工作区的内容是从git上获取的

[root@linux-node1 ~]# cd /root/jenkins_home/workspace/my-freestyle-job/ [root@linux-node1 my-freestyle-job]# git branch -a * (detached from 51916b1) remotes/origin/1-demo-issue remotes/origin/master
安装可选插件


浙公网安备 33010602011771号