jenkins

作者: 快去学习不然怎么去看aimer | 来源:发表于2019-10-23 15:49 被阅读0次

    docker-compose.yaml

      jenkins:
        restart: always
        image: centos7-jenkins-plugins
        container_name: docker_jenkins
    #    volumes:
    #      - "./jenkins_home/:/var/lib/jenkins/"
        ports:
          - '222:22'
          - '8091:8080'
        privileged: true
        command: /usr/sbin/init
        networks:
          - qfedu-gp
      web:
        restart: always
        image: centos7-python3.7
        container_name: docker_web
        volumes:
          - "./web/home/:/home/"
        ports:
          - '8090:80'
        networks:
          - qfedu-gp
        privileged: true
        command: /usr/sbin/init
    networks:
      qfedu-gp:
    

    启动之后安装插件

    Ansible plugin
    Ant Plugin
    Blue Ocean
    Build Timeout
    Email Extension Plugin
    Git Parameter Plug-In
    Gitlab Hook Plugin
    GitLab Plugin
    Maven Invoker plugin
    Maven Integration plugin
    Publish Over SSH
    SSH plugin
    SSH Slaves plugin
    Rebuilder
    Safe Restart
    

    smtp功能

    在Manage Jenkins里选择configuration。

    Jenkins Location:
    Jenkins URL: http://192.168.1.2:8080/(填写访问地址)
    System Admin e-mail address: 1@rou.com
    
    E-mail Notification:
    SMTP server:  smtp.rou.com
    Default user e-mail suffix : @rou.com
    勾选Use SMTP Authentication
    用户名:邮箱地址(与系统管理员的邮箱一致)
    密码:授权码
    SMTP Port:25(勾选SSL后端口为465)
    勾选Test configuration by sending test e-mail
    填写自己的邮箱地址
    点击test configration(测试)
    
    

    SSH互信

    Publish over SSH:
    
    key:为被服务的机器的私钥
    hostname:被服务机器的ip
    username:root(使用的远端用户)
    Remote Directory:远端的目录
    点击test configration(测试是否成功)
    
    

    构建gitlab项目

    在gitlab中:
    建立新项目并添加new file: show_system_info.sh
    show_system_info.sh的内容:
         echo "-----------主机名-------------"
         hostname
         touch /app/rourou.txt
         echo "hello" rourou1.txt
         free -h 
         uptime
    
    复制clone地址
    点击new item
    输入项目名,选择项目类型,这里选择freestyle item
    Description:添加描述
    Source Code Management:
         选择git:
         Repository URL:填写复制的clone地址
         Credentials:选择登陆的用户
         或者点击ADD:
             选择git方式(前提是jenkins以把公钥传给了gitlab)或username and passeord 方式登陆gitlab
             
    选择build:
    Name:选择被管理的机器
    
    Source files:(show_system_info.sh)这里填写的是打好包的路径,是相对路径,相对于工作空间目录的,工作空间默认是在 $JENKINS_HOEM/workspace 目录下。每次新建一个构建任务时,会在此目录下创建一个和任务名同名的目录(比如:HelloMaven),在此目录下存放从远程代码库拉取的源代码,并且构建完成的文件(比如jar 包)也会在 HelloMaven/target 目录下。
    
    Remove prefix:是在把打好包的文件传输到远程应用服务器时,不希望被创建的目录名。 这个目录名必须是在 Source files 选项中填写的路径最前面的部分中。
    
    Remote directory:(code)远程应用服务器的目录,这个目录假如没有会被自动创建,但是此目录是给相对路径,相对于之前在系统设置中的 SSH Servers 中配置的服务器端路径
    
    Exec command:(sh /app/code/show_system_info.sh)指构建后在远程应用服务器上执行的命令。
    
    保存后,点击Build now
    

    待构建完成之后,点击console output查看

    <pre class="console-output" style="box-sizing: border-box; white-space: pre-wrap; overflow-wrap: break-word; margin: 0px; color: rgb(51, 51, 51); font-size: 13px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">Started by an SCM change
    Running as SYSTEM
    Building in workspace /var/lib/jenkins/workspace/jenkins projects
    using credential 1
     > git rev-parse --is-inside-work-tree # timeout=10
    Fetching changes from the remote Git repository
     > git config remote.origin.url [http://10.0.122.124:8081/rourou/ll.git](http://10.0.122.124:8081/rourou/ll.git) # timeout=10
    Fetching upstream changes from [http://10.0.122.124:8081/rourou/ll.git](http://10.0.122.124:8081/rourou/ll.git)
     > git --version # timeout=10
    using GIT_ASKPASS to set credentials get system info script
     > git fetch --tags --progress [http://10.0.122.124:8081/rourou/ll.git](http://10.0.122.124:8081/rourou/ll.git) +refs/heads/*:refs/remotes/origin/*
     > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
     > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
    Checking out Revision c86f70e2dc86a336bbbd912c77c6f7b6a9260b6b (refs/remotes/origin/master)
     > git config core.sparsecheckout # timeout=10
     > git checkout -f c86f70e2dc86a336bbbd912c77c6f7b6a9260b6b
    Commit message: "Update show_system_info.sh"
     > git rev-list --no-walk f395fc2203b5509378ddb7e105a719e176438dfe # timeout=10
    SSH: Connecting from host [74a3c2c9ae63]
    SSH: Connecting with configuration [webserver1] ...
    SSH: EXEC: STDOUT/STDERR from command [sh /app/code/show_system_info.sh] ...
    -----------主机名-------------
    49a6713a34ee
    hello rourou1.txt
                  total        used        free      shared  buff/cache   available
    Mem:           7.7G        6.0G        182M        762M        1.5G        530M
    Swap:           19G        457M         19G
     07:06:23 up  7:19,  0 users,  load average: 0.52, 0.53, 0.59
    SSH: EXEC: completed after 200 ms
    SSH: Disconnecting configuration [webserver1] ...
    SSH: Transferred 1 file(s)
    Build step 'Send files or execute commands over SSH' changed build result to SUCCESS
    Finished: SUCCESS</pre>
    

    到被管理的服务器上查看构建的目录

    |-- code
    |   `-- show_system_info.sh
    `-- rourou.txt
    

    相关文章

      网友评论

          本文标题:jenkins

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