zoukankan      html  css  js  c++  java
  • [Jenkins][GitHub]2 持续集成环境初探

    预计阅读时间:30分钟

    部署环境:Jenkins ver. 2.61 + Centos7 + Java 1.8

    参考链接: http://www.jianshu.com/p/22b7860b4e81

    目标:在之前搭建的Jenkins实现如下操作,了解源码管理/构建触发器/构建环境/Bindings构建/构建后操作等基本配置操作,利用Jenkins实现初步的持续集成

    • github仓库的使用

    • makefile的使用

    • 脚本的使用

    [步骤1 配置邮箱通知] 参考链接 http://www.debugrun.com/a/T9PeIVx.html  

    :126邮箱必须开通客户端授权认证,然后在Jenkins中代替邮箱密码在客户端登录邮箱使用

     为了避免密码泄露造成邮箱安全隐患,需设置客户端授权码,用授权码代替密码在客户端登录邮箱

    [步骤2 添加授权认证 Add Credentials]参考http://www.jianshu.com/p/22b7860b4e81 

    1 在github上创建access token

    Tokens you have generated that can be used to access the GitHub API.

    Make sure to copy your new personal access token now. You won’t be able to see it again!

    XXXXXXXXXXXX

    [步骤3 Create sample go project with makefile]

    makefile编写参考http://www.tuicool.com/articles/ueIfAve

    1. 在github项目中添加如下目录结构 DevOps/Jenkins/

    2. main.go

    package main
    
    import "fmt"
    
    // Variables to identify the build
    
    var (
     Version = "1.0.0"
     Build = "2017-05-17"
    )
    
    func main() {
    fmt.Println("Version: ", Version)
    fmt.Println("Build time: ", Build)
    }
    

     3. Makefile

    # Default target: builds the project
    build:
    	go build
    
    # Installs our project: copies binaries
    install:
    	go install
    
    # Cleans our project: deletes binaries
    clean:
    	go clean

    [步骤4 配置github以及hook,Config github/git hook] 

    参考 http://www.jianshu.com/p/22b7860b4e81  进行配置

    其中Github的项目配置如下 ,链接地址为  http://<Jenkins IP:8080>/github-webhook/

    其中Execute shell 参考编写如下

    pwd
    ls
    go version
    echo "hello Jenkins"
    make -C src/DevOps/Jenkins
    

    坑 1.Jenkins服务器上需要安装git ,github上需要配置access key,然后在Jenkins上配置相应的权限

    坑2. 我找了1个小时也没有找到Build when a change is pushed to GitHub,最后google到了答案如下:

    On the v1.25.1 release of the GitHub plugin, trigger Build when a change is pushed to GitHub has been renamed to 

    GitHub hook trigger for GITScm polling.

    [步骤5]持续集成测试环境之初显威力。

    由于Hook了github,因此每次commit都会触发build操作,然后检查项目构建历史

    预告:下期“持续集成进阶”想要实现的目标

    • dockerhub的调用

    • ansible 配置的调用

    • Job的依次调用

  • 相关阅读:
    用Python获取Linux资源信息的三种方法
    对python中元类的理解
    一道有趣的和编程无关的编程题思考
    Python编程进阶
    函数计算的 Python手册小问题
    Linux 命令
    pyechart
    KV数据库Redis
    微博API 学习记录
    非阻塞式的 requests.post 学习
  • 原文地址:https://www.cnblogs.com/carol2000/p/6868210.html
Copyright © 2011-2022 走看看