美文网首页
jenkins十分钟上手

jenkins十分钟上手

作者: mafa1993 | 来源:发表于2022-07-11 20:51 被阅读0次

jenkins

  1. jenkins 市场占有率90%

gitlab和jekins的过程

  1. 提交代码到gitlab
  2. jenkins触发器(可以是使用githook 主动触发,或者jenkins定时轮询gitlab)查看代码是否有变化,有变化以后会获取代码重新构建
  3. 自动或手动同步代码到需要部署的机器
  4. 利用shell脚本触发构建过程
  5. jenkins就是写一些shell脚本,会在不同的过程中执行

jenkins 安装

  1. 可以利用待编包直接安装

配置

  1. /etc/sysconfig/jenkins配置文件
JENKINS_USER="root"  // jenkins 用户
JENKINS_PORT="8080" //配置端口
## Path: Development/Jenkins 
## Description: Jenkins Automation Server 
## Type: string ## Default: "/var/lib/jenkins" 
## ServiceRestart: jenkins 
## Directory where Jenkins store its configuration and working 
# files (checkouts, build reports, artifacts, ...). 
#
JENKINS_HOME="/var/lib/jenkins" 

## Type: string ## Default: "" 
## ServiceRestart: jenkins 
## Java executable to run Jenkins # When left empty, we'll try to find the suitable Java.
#
JENKINS_JAVA_CMD=""

## Type: string 
## Default: "jenkins" 
## ServiceRestart: jenkins
## Unix user account that runs the Jenkins daemon 
# Be careful when you change this, as you need to update 
# permissions of $JENKINS_HOME and /var/log/jenkins. 
#
JENKINS_USER="root"

## Type: string 
## Default: "false" 
## ServiceRestart: jenkins 
## Whether to skip potentially long-running chown at the 
# $JENKINS_HOME location. Do not enable this, "true", unless 
# you know what you're doing. See JENKINS-23273. 
##
JENKINS_INSTALL_SKIP_CHOWN="false" 

## Type: string ## Default: "-Djava.awt.headless=true" 
## ServiceRestart: jenkins 
## Options to pass to java when running Jenkins.
#
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true" 

## Type: integer(0:65535) 
## Default: 8080 ## ServiceRestart: jenkins 
## Port Jenkins is listening on. # Set to -1 to disable 
#
JENKINS_PORT="8080" ## Type: string 
## Default: ""
## ServiceRestart: jenkins 
## IP address Jenkins listens on for HTTP requests. 
# Default is all interfaces (0.0.0.0). #
JENKINS_LISTEN_ADDRESS="" 

## Type: integer(0:65535) 
## Default: "" 
## ServiceRestart: jenkins 
## HTTPS port Jenkins is listening on. 
# Default is disabled. 
#
JENKINS_HTTPS_PORT="" 

## Type: string ## Default: "" 
## ServiceRestart: jenkins 
## Path to the keystore in JKS format (as created by the JDK 'keytool'). 
# Default is disabled. 
#
JENKINS_HTTPS_KEYSTORE="" 

## Type: string ## Default: "" 
## ServiceRestart: jenkins 
## Password to access the keystore defined in JENKINS_HTTPS_KEYSTORE. 
# Default is disabled. #
JENKINS_HTTPS_KEYSTORE_PASSWORD="" 

## Type: string ## Default: "" 
## ServiceRestart: jenkins 
## IP address Jenkins listens on for HTTPS requests. # Default is disabled. #
JENKINS_HTTPS_LISTEN_ADDRESS="" 

## Type: integer(0:65535) 
## Default: "" 
## ServiceRestart: jenkins 
## HTTP2 port Jenkins is listening on.
# Default is disabled. 
## Notice: HTTP2 support may require additional configuration, see Winstone # documentation for more information. #
JENKINS_HTTP2_PORT="" 

## Type: string ## Default: "" 
## ServiceRestart: jenkins 
## IP address Jenkins listens on for HTTP2 requests. # Default is disabled. 
## Notice: HTTP2 support may require additional configuration, see Winstone 
# documentation for more information. #
JENKINS_HTTP2_LISTEN_ADDRESS="" 

## Type: integer(1:9) 
## Default: 5 
## ServiceRestart: jenkins 
## Debug level for logs -- the higher the value, the more verbose. 
# 5 is INFO. #
JENKINS_DEBUG_LEVEL="5" 

## Type: yesno ## Default: no 
## ServiceRestart: jenkins 
## Whether to enable access logging or not. #
JENKINS_ENABLE_ACCESS_LOG="no"

## Type: integer ## Default: 100 
## ServiceRestart: jenkins 
## Maximum number of HTTP worker threads. #
JENKINS_HANDLER_MAX="100" 

## Type: integer ## Default: 20 
## ServiceRestart: jenkins ## Maximum number of idle HTTP worker threads. #
JENKINS_HANDLER_IDLE="20" 

## Type: string ## Default: "" 
## ServiceRestart: jenkins 
## Folder for additional jar files to add to the Jetty class loader. 
# See Winstone documentation for more information.
# Default is disabled.
#
JENKINS_EXTRA_LIB_FOLDER=""

## Type: string ## Default: ""
## ServiceRestart: jenkins 
## Pass arbitrary arguments to Jenkins. 
# Full option list: java -jar jenkins.war --help #
JENKINS_ARGS=""
  1. 修改配置后重启jenkins
  2. 修改jenkins的插件源
// /var/lib/jenkins/updates下的default.json
sed -i 's/www.google.com/www/baidu.com/g/' default.json
sed -i 's/updates.jenkins-ci.org\/download/mirrors.tuma.tsinghua.edu.cn\/jenkins/g' default.json

sed -i 's/updates.jenkins.io\/download/mirrors.tuna.tsinghua.edu.cn\/jenkins/g'  default.json

service jenkins restart
  1. 登录jenkins,首次登录会提示去某个路径查看密码,查看后填入即可
  2. 安装插件, 全选即可
  3. 创建管理员
  4. 然后创建实例 进入管理页面
  5. 界面上提示错误的话,点击纠正
  6. 安装插件:gitlab、publish over ssh、git parameter

使用

  1. 新建任务,输入任务名
  2. 丢弃构建历史部分,配置构建缓存的保存天数或者个数
  3. 点源码管理,输入git仓库的地址
  4. 指定拉取的分支名,例如*/master
  5. 在jenkins上生成密钥加到gitlab上
  6. 构建选择ssh(先在Dashboard->系统管理->系统配置 上创建所有的生产机器)
  7. source file一般填入*/
  8. remote directory 填入部署项目时候,要部署到的目录
  9. exec command 里面填写shell命令,可以执行shell脚本,重新执行编译过程等
  10. 构建触发器:
    • 轮询scm 定时去查看代码是否发生了变化,如果发生了变化,就更新,使用crontab格式填写日程表
    • 定时构建,定时拉取,不管代码是否有更新,使用crontab格式填写日程表 分钟 小时 日期 月份 星期
    • 手工构建,在jenkins中手工点击构建
  11. 多台机器构建,点击add server

项目发布

  1. 在jenkins项目中,点击配置,修改exec Command
  2. 将原有的go服务停止,执行go编译命令,运行go服务
  3. 在merge request 中进行code review
  4. settings->repository-> protect a branch 设置受保护的分支

相关文章

网友评论

      本文标题:jenkins十分钟上手

      本文链接:https://www.haomeiwen.com/subject/rwwabrtx.html