• 【原创】编程基础之Jekins


    Jenkins 2.164.2

    官方:https://jenkins.io

    一 简介 

    Build great things at any scale

    The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.

    jenkins支持数百种插件支持构建、部署和自动化;

    Jenkins is a self-contained, open source automation server which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software.

    Jenkins can be installed through native system packages, Docker, or even run standalone by any machine with a Java Runtime Environment (JRE) installed.

    任何公司都面临项目部署的问题,而项目部署抽象起来包括:1)指定分支和版本;2)从代码库下载代码;3)编译和打包;4)发布到远程服务器;5)重启应用;6)回滚;

    发布到远程服务器的根据需要可以是jar、war、docker image或文件夹;

    jenkins让你通过插件、配置、脚本的方式完成上述的一切;

    二 安装

    sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
    sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
    yum install jenkins

    启动

    systemctl start jenkins
    systemctl enable jenkins
    systemctl status jenkins

    启动之后访问

    http://localhost:8080

    如果默认端口8080有冲突,可以修改

    vi /etc/init.d/jenkins
    export JENKINS_PORT=8080

    首次登录随机密码在这里

    /var/lib/jenkins/secrets/initialAdminPassword

    按照向导操作即可;

    三 使用

    常用插件

    Git (代码库)

    Maven (构建和打包)

    Publish Over SSH (远程拷贝文件并执行命令)

    SSH (远程执行命令)

    Zentimestamp (支持 ${BUILD_TIMESTAMP})

    Extended Choice Parameter Plug-In (用于回滚)

    创建一个新的项目

    1 先在Credentials中增加git账号和服务器ssh账号及密码;

    2 然后在Manage Jenkins - Configure System中配置ssh服务器相关;

    3 创建项目

    3.1 New Item

    3.2 Freestyle project

    3.3 Config

    3.3.1 Source Code Management

      添加git repository url并选择刚才添加的git账号;

    3.3.2 Build

      Invoke top-level Maven targets (执行maven goal)

      Execute shell (本地执行shell)

      Execute shell script on remote host using ssh (远程执行shell)

    3.3.3 Post-build Actions

      Send build artifacts over SSH (远程拷贝文件并执行shell)

    这样一个简单的项目部署就完成了

    在shell中可以使用很多jenkins的环境变量,比如 WORKSPACE,JOB_NAME,BUILD_TAG,GIT_COMMIT等,详见:

    http://localhost:8080/env-vars.html/

    目录结构

    jenkins目录位于

    /var/lib/jenkins

    workspace目录位于

    /var/lib/jenkins/workspace

    job目录为

    /var/lib/jenkins/workspace/${JOB_NAME}

    代码下载和编译打包都在job目录中,比如target目录;

    参考:
    https://github.com/jenkinsci/docker/blob/master/README.md

    https://pkg.jenkins.io/redhat-stable/

  • 相关阅读:
    python requests 上传excel数据流
    No module named 'requests_toolbelt'
    code
    pytest 打印调试信息
    python3 获取日期时间
    Java单元测试之JUnit篇
    The import junit cannot be resolved解决问题
    什么是索引
    python3 ini文件读写
    js 测试题
  • 原文地址:https://www.cnblogs.com/barneywill/p/10827217.html
Copyright © 2020-2023  润新知