jenkins基础知识整理

(1)简介

jenkins是一个用java编写的开源的持续集成(Continuous integration,简称CI)工具。它提供的1000多种插件几乎可以支持所有的自动化工作,通常用于构建工程,自动化测试,静态代码分析以及自动部署等。jenkins自动化地执行重复性的任务,可以快速地发现bug,为开发人员节省了大量时间,使其集中精力于那些机器无法完成的工作。

(2)安装

jenkins可以通过本地系统安装包、Docker安装,甚至可以在任何安装了 Java运行环境的机器上独立运行。参考:https://jenkins.io/doc/
在Ubuntu上安装jenkins,执行下列指令即可:
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c ‘echo deb http://pkg.jenkins.io/debian-stable binary/ >
/etc/apt/sources.list.d/jenkins.list’
sudo apt-get update
sudo apt-get install jenkins
这种安装方式会:
将jenkins加入到开机自启动项中(/etc/init.d/jenkins);
创建”jenkins”用户来运行该服务;
将jenkins的console log保存在/var/log/jenkins/jenkins.log中;
按照/etc/default/jenkins文件中的配置参数启动jenkins.
设置jenkins监听8080号端口;

(3)使用

1)访问:
jenkins服务器本地访问:http://localhost:8080/
我们的jenkins服务器访问网址:http://172.29.40.153:8080/ 用签核账号登录,操作权限因人而异.
2)查看全局设置:
点击左侧的系统管理栏,可以通过"系统设置"查看jenkins的全局配置信息.其中一个重要的配置项就是jenkins用户的主目录/var/lib/jenkins ,jenkins上的大多数操作都在这个目录下进行,这个目录下的所有文件及目录的拥有者最好都设置为jenkins,否则运行程序时很容易出现权限问题.
3)创建一个项目并构建
在jenkins服务器网页中直接新建一个item并选择项目类型,并配置详细的项目参数即可.其中项目要执行的动作以pipeline的形式执行.

==备注==

pipeline介绍(摘自jenkins官网):
Jenkins Pipeline is a suite of plugins which supports implementing and integrating continuous delivery pipelines into Jenkins. Pipeline provides an extensible set of tools for modeling simple-to-complex delivery pipelines “as code”.
Pipelines are made up of multiple steps that allow you to build, test and deploy applications. Jenkins Pipeline allows you to compose multiple steps in an easy way that can help you model any sort of automation process.
Pipeline contians Declarative Pipeline and Scripted Pipeline.
Declarative Pipeline is a relatively recent addition to Jenkins Pipeline which presents a more simplified and opinionated syntax on top of the Pipeline sub-systems.All valid Declarative Pipelines must be enclosed within a pipeline block, for example:
pipeline { /* insert Declarative Pipeline here */ }
Scripted Pipeline, like Declarative Pipeline, is built on top of the underlying Pipeline sub-system. Unlike Declarative, Scripted Pipeline is effectively a general purpose DSL built with Groovy. Most functionality provided by the Groovy language is made available to users of Scripted Pipeline, which means it can be a very expressive and flexible tool with which one can author continuous delivery pipelines. Scripted Pipeline is serially executed from the top of a Jenkinsfile downwards, like most traditional scripts in Groovy or other languages. Providing flow control therefore rests on Groovy expressions, such as the if/else conditionals, for example:
node {
stage(‘Example’) {
if (env.BRANCH_NAME == ‘master’) { echo ‘I only execute on the master branch’ } else { echo ‘I execute elsewhere’ }
}
}
持续集成参考资料:
http://www.ruanyifeng.com/blog/2015/09/continuous-integration.html
pipeline语法介绍:
https://jenkins.io/doc/book/pipeline/syntax/#_footnote_2

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐