Easypack之Alpine容器系列 Jenkins之pipeline集成

在Jenkins的alpine容器中我们集成了缺省的用户名和密码,但是更多的手动作业可以进一步按需进行集成,比如在Jenkins2之后所提供的强大的pipeline功能,这些都是通过plugin方式进行集成的。

安装方式

jenkins的plugin的安装方式有很多种,可以将jenkins安装之后进行手动安装,或者下载之后进行安装。本文使用Jenkins所提供的plugins.sh进行批处理安装。Jenkins提供了如下方式进行安装plugin:

文件 说明
plugins.sh 将plugins.txt中记载的plugin全部安装
plugins.txt 安装对象plugin

plugins.txt格式

plugin格式 plugin名称 版本号

安装方式

plugin安装方式 plugins.sh plugins.txt

Dockerfile修正

在dockerfile中作类似如下内容,保证镜像创建时相关plugin会被安装。

COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN /usr/local/bin/plugins.sh /usr/share/jenkins/ref/plugins.txt
  • 1
  • 2

Jenkins Pipeline

什么是Jenkins Pipeline

Jenkins Pipeline是一组plugin的集合,通过这些plugin,使得Jenkins实现了持续交付流水线的功能。而且通过其所提供的DSL使得Jenkins具有了将此条部署流水线代码化的能力。随后我们将会使用具体的例子来看一下如何使用Jenkins的pipeline DSL来定义一条部署流水线。

Pipeline所需plugin

直接倚赖

workflow-aggregator 2.5
pipeline-input-step 2.5
workflow-job 2.9
workflow-basic-steps 2.3
workflow-durable-task-step 2.9
workflow-api 2.10
workflow-cps 2.25
workflow-support 2.13
workflow-cps-global-lib 2.6
workflow-multibranch 2.12
pipeline-stage-view 2.4
workflow-scm-step 2.3
workflow-step-api 2.9
pipeline-model-definition 1.0.1
pipeline-stage-step 2.2
pipeline-build-step 2.4
pipeline-milestone-step 1.3
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

间接依赖

希望生产环境上的CI服务器所安装的Plugin一个不多一个不少,版本能够得到控制,必须了解其之间的关联,虽然有包管理工具的辅助,基本原理的理解还是必不可少的, Jenkins结合Nexsus或者Artifactory进行解决是目前流行的方式,详细方式将在后续文章中进一步展开.

momentjs 1.1
handlebars 1.1
pipeline-rest-api 2.5
jquery-detached 1.2.1
branch-api 2.0.6
structs 1.5
cloudbees-folder 5.17
scm-api 2.0.4
script-security 1.25
mailer:1.19
display-url-api 1.1.1
junit 1.20
support-core 2.38
metrics 3.0.0
credentials 2.1.11
async-http-client 1.7.8
jackson2-api 2.5.4
durable-task 1.13
git-client 1.19.7
git-server 1.5
ssh-credentials 1.12
ace-editor 1.1
credentials-binding 1.10
plain-credentials 1.3
docker-workflow 1.9
icon-shim 1.0.3
authentication-tokens 1.1
pipeline-model-api 1.0.1
pipeline-model-declarative-agent 1.0.1
pipeline-stage-tags-metadata 1.0.1
docker-commons 1.6
pipeline-graph-analysis 1.1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

启动容器

Easypack的Alpine版本已经更新到了Jenkins最新的2.47,在此基础之上的pipeline进行安装。详细的使用方式如下:

项目 详细
前提条件 docker安装完毕,运行状态,并且能够联网
取得镜像 docker pull liumiaocn/jenkins
运行 docker run -d -p 8080:8080 -p 50000:50000 –name jenkins liumiaocn/jenkins
[root@liumiaocn ~]# docker pull liumiaocn/jenkins
Using default tag: latest
Trying to pull repository docker.io/liumiaocn/jenkins ...
latest: Pulling from docker.io/liumiaocn/jenkins

b7f33cc0b48e: Already exists
43a564ae36a3: Already exists
b294f0e7874b: Already exists
8f13f5993c6e: Pull complete
e0a4f2d0738b: Pull complete
70f79e3e04b1: Pull complete
2240fc0ff300: Pull complete
78e5e66fb198: Pull complete
bd02da8b0ee9: Pull complete
5f55bb586f95: Pull complete
b85ee00cd028: Pull complete
55b6c74cc85a: Pull complete
663debea7d60: Pull complete
0a63a10ee539: Pull complete
c815424b9b61: Pull complete
cf00a6f1476d: Pull complete
af72264b1901: Pull complete
Digest: sha256:2f2a88c9fb6310938c2f158634a214e8fccafc4553b148e01dd9f07569a094e2
Status: Downloaded newer image for docker.io/liumiaocn/jenkins:latest
[root@liumiaocn ~]# docker run -d -p 8080:8080 -p 50000:50000 --name jenkins liumiaocn/jenkins
614804339b01562fc1b18faa96b7cb7780a1f9fcb54d371e6a093eacf1815602
[root@liumiaocn ~]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

画面确认

使用以下信息登陆Jenkins

项目 详细
用户名 admin
密码 admin
URL http://192.168.32.123:8080 (请使用自己机器的IP)

跳过Plugin的安装,即可看到已经集成Pipeline之后的Jenkins画面
这里写图片描述

创建一个Pipeline的Job
这里写图片描述

设定pipeline
这里写图片描述

Jenkinsfile内容

pipeline {
    agent any 

    stages {
        stage('Build') { 
            steps { 
                sh 'echo Build stage ...' 
            }
        }
        stage('Test'){
            steps {
                sh 'echo Test stage ...' 
            }
        }
        stage('Deploy') {
            steps {
                sh 'echo Deploy stage ...' 
            }
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

构建
这里写图片描述

Log确认
这里写图片描述

参照

https://jenkins.io/doc/book/pipeline/syntax/
https://jenkins.io/doc/book/pipeline/
https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Plugin
https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Stage+View+Plugin

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自www.cnblogs.com/firsttry/p/10294044.html