安装和部署Jenkins

安装和部署Jenkins

环境

操做系统:ubuntu 14.04.4 LTSjava

下载Jenkins

wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/war-stable/2.32.3/jenkins.war

安装Jenkins

Jekins有三种方式进行安装:python

  • 能够经过本地的包文件直接安装
  • 或者使用Docker进行安装;
  • 还能够下载war文件,以后安装在一台带有JRE的机器上。

下面介绍的是最后一种安装方式。须要至少Java7以上的(推荐Java 8)环境。 至少具备512MB内存。web

  1. 下载jenkins.war。(上面已经说明了)docker

  2. 经过SSH链接到ubuntu上,而后运行java -jar jenkins.warubuntu

    Jenkins initial setup is required. An admin user has been created and a password generated. Please use the following password to proceed to installation:浏览器

    b3ce86bc4ab64188bee4032f3845d113maven

    This may also be found at: /root/.jenkins/secrets/initialAdminPasswordui

上面的密码会在下个步骤中使用。操作系统

  1. 打开web浏览器,访问http://localhost:8080,接下来安装页面上的说明进行部署
  2. 许多的Pipeline例子须要安装Docker。

创建Pipeline

最快的方式是,复制下面的例子到你的代码版本库中,并使用Jenkinsfile做为文件名。code

  1. 创建jenkinsfile

下面是针对Java语言的:

Jenkinsfile (Declarative Pipeline)
    pipeline {
        agent { docker 'maven:3.3.3' }
        stages {
            stage('build') {
                steps {
                    sh 'mvn --version'
                }
            }
        }
    }

针对Python语言的:

Jenkinsfile (Declarative Pipeline)
    pipeline {
        agent { docker 'python:3.5.1' }
        stages {
            stage('build') {
                steps {
                    sh 'python --version'
                }
            }
        }
    }
  1. 在Jenkins中点击New Item菜单

jenkins_new_item

  1. 给new item输入名称,并选择Multibranch Pipeline
  2. 点击Add Source按钮, 选择仓库类型
  3. 点击Save按钮来运行Pipeline。

参考

https://jenkins.io/doc/pipeline/tour/hello-world/